From: Adam Prescott Date: 2011-11-10T05:27:10+09:00 Subject: Re: Strings are not equal --14dae93b6356a9278d04b1531c89 Content-Type: text/plain; charset=UTF-8 On Wed, Nov 9, 2011 at 20:16, Mike S. wrote: > I am testing two strings to see if they are equal. > One string is just a simple string: "\17" > The other is parsed to: "\17" > You might think so, but nope: >> "\17" => "\u000F" >> "\1#{7}" => "\u00017" >> "\001" => "\u0001" >> "\01" => "\u0001" >> "\1" => "\u0001" => "\0017" >> "\u00017" The \ causes things to be escaped, with the subsequent 3 digits being an octal number. "\001" == "\01" == "\1", and "\1#{7}" == "\1" + "#{7}" == "\001" + "#{7}" To see the octal base: >> "\001\005\1\01\010\060".bytes.to_a => [1, 5, 1, 1, 8, 48] since, for example, 6*8^1 = 48. And since it expects numbers 0-7, 8 breaks you out of it: >> "\08" => "\u00008" In other words, "\08" == "\008" == "\0008" == "\000" + "8". Finally, "\8" == "8". You can extend this to, e.g., "\xFA" for hexadecimal. Beware the escaping character. :) --14dae93b6356a9278d04b1531c89--