From: Arnaud Bergeron Date: 2006-07-29T05:21:09+09:00 Subject: Re: Finding "\" in a string On 7/28/06, Eric Armstrong wrote: > I'm going crazy, right? Surely it is possible > to find a backslash (\) in a string, and > replace it with two backslashes. That's simple, > right? Just gsub("\\", '\\'). That's all there > is to it. irb> puts '\\' \ => nil You are replacing single slashes with sigle slashes. > Except that... > > #!/usr/bin/env ruby > > testpath = "\\foo\\bar" > p testpath # => "\\foo\\bar" --representation > puts testpath # => \foo\bar --what you see > > result = testpath.gsub("\\", '\\') > p result # => "\\foo\\bar" > (represenation unchanged. Should be "\\\\foo\\\\bar") > > puts result # => \foo\bar > (unchanged. should be \\foo\\bar) > > I've tried lots of gsub variations, like > /\\/, '\\', "\\\\", and anything else I could > think of that came even close to being sensible, > but I've yet to find anything that works. > > My workaround will be to add a sed script to > filter the input. But surely that isn't necessary. > Is it? > -- "i think we should rewrite the kernel in java since it has good support for threads." - Ted Unangst