From: Brian Candler Date: 2010-01-08T18:57:56+09:00 Subject: Re: Stopping String Escaping. Phil Cooper-king wrote: > un_parsed =< \\ > ENDOF Unfortunately, here the \\ is being turned into a single backslash by ruby, the same as inside a quoted string. In other words, the same as this: irb(main):001:0> "\\".size => 1 irb(main):002:0> '\\'.size => 1 The simplest way of preventing this is to read unparsed from a file, or you can have an inline dataset at the end of your source code, like this: unparsed = DATA.read ... rest of your code goes here __END__ \\ > I expect the \ to be lost in puts > tho. No, puts *never* converts two backslashes into one. If your string contains two backslashes, puts will show two backslashes. > Using the dump I see the double slash is still there. No, this is the opposite. String#inspect turns a raw string into a quoted string for display purposes, and as part of this quoting a single backslash is displayed as two backslashes. Look at this: irb(main):001:0> s = 92.chr => "\\" irb(main):002:0> s.size => 1 irb(main):003:0> puts s \ => nil irb(main):004:0> s2 = s + s => "\\\\" irb(main):005:0> s2.size => 2 irb(main):006:0> puts s2 \\ => nil Hopefully it's clear from the above that string s has one character (a single backslash), and s2 has two backslashes. But these are displayed in quoted form in irb as "\\" "\\\\" respectively. puts displays them correctly. Similarly, a single newline character is displayed as backslash-n when inspect gives the quoted form; whereas puts actually prints a newline. irb(main):009:0> nl = 10.chr => "\n" irb(main):010:0> nl.size => 1 irb(main):011:0> puts nl => nil So try your test case again: (1) Use the DATA.read / __END__ to get the test source in (2) Use 'puts' and not 'dump' to see clearly what you have -- Posted via http://www.ruby-forum.com/.