From: William James Date: 2008-03-13T15:24:53+09:00 Subject: Re: mechanize 0.7.3 Released Roger Pack wrote: > Questions: > > The following ways all recreate my original string, however I am having > trouble getting the comparison work to itself expressed in string > form--it's like the string form doesn't express all the inside chars or > something--am I missing something? Is there a way to recreate the > string along the lines of "dent?\226" and, as a follow up, is > complicated_string.inspect just not displaying the interior characters > right? > > > >> bytes = [100, 101, 110, 116, 226, 60, 56, 48, 62, 60, 57, 57, 62, 115, > ?> 32, 112, 114, 101, 118, 105, 111, 117] > >> bytes.pack('C*') == "dent?<80><99>s previou" > => false > >> str = "" > => "" > >> > ?> for code in bytes > >> str << code.chr > >> end > => [100, 101, 110, 116, 226, 60, 56, 48, 62, 60, 57, 57, 62, 115, 32, > 112, 114, 101, 118, 105, 111, 117] > >> str == "dent?<80><99>s previou" > => false > >> str = bytes.map{|n| n.chr}.join > => "dent?<80><99>s previou" > >> str == "dent?<80><99>s previou" > => false irb(main):002:0> ?A => 65 irb(main):003:0> ?? => 63 irb(main):004:0> 226.chr => "\342" irb(main):005:0> puts 226.chr à The character whose ASCII code is 226 is not a question mark. The ASCII code of a question mark is 63. irb(main):008:0> puts [100, 101, 110, 116, 226].map{|n| n.chr}.join dentà irb(main):009:0> "342".to_i(8) => 226 Octal for 226 is 342.