From: Mike Stok Date: 2011-05-02T04:40:31+09:00 Subject: Re: >> string = "\37" # => "\037" -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 2011-05-01, at 3:12 PM, Geometric Patterns wrote: > Hi. > > I want to create a string with the backslash character followed by the > number 37. Whenever I try to do this, ruby always creates "\037" ! > > e.g. in irb: > >>> string = "\37" > => "\037" > > How can I avoid this? I tried different quoting, escaping, etc. > > I am missing something fundamental here :-( > > Any advice gratefully received. What different quoting did you try? There are a couple of ways to start looking at this - if you need to use double quotes then you can escape the backslash, and if you don't need to use double quotes then the number of things the backslash escapes are reduced. You should also be aware that irb's result display is different from what you'd see with puts. For example: >> string = '\37' => "\\37" >> puts string \37 => nil >> string = "\\37" => "\\37" >> puts string \37 => nil Hope this helps, Mike - -- Mike Stok http://www.stok.ca/~mike/ The "`Stok' disclaimers" apply. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (Darwin) iEYEARECAAYFAk29txgACgkQnsTBwAWZE9qwRgCdFd5Dbzf7QoE0xIXSuHBTZjHZ DqQAoI3/GPmDa89kwIVJH5CeXu633YU9 =7UUs -----END PGP SIGNATURE-----