From: Hal Fulton Date: 2003-11-12T07:26:19+09:00 Subject: Re: Backslash substitution question Ron Coutts wrote: > I'm having trouble with backslashes and I don't know what is wrong. I > can't seem to write and expression that will evaluate to a string > containing a single backslash character as in "\". It seems that "\\" > in Ruby evaluates to "\\" not to "\" as I would expect. Below are a few > things I've tried. If anyone could send back a quick answer it would be > much appreciated. > > res = "c:/foo/bar".gsub(/\//, "\\") # -> c:\\foo\\bar This one works. You're getting confused by either irb or by calling p. You're seeing the escaped form, but it's not stored that way internally. Note that res.length is 10, not 12. Hal