From: Rob Biedenharn Date: 2009-01-20T10:44:17+09:00 Subject: Re: Gsub!("\n","\n") Are you seeing something like: irb> look = 'here is a " and I\'ll put a \' here, too' => "here is a \" and I'll put a ' here, too" irb> puts look here is a " and I'll put a ' here, too => nil The rules for what needs to be escaped depend on the kind of quotes used. Are you seeing output that is shown in double quotes to indicate that it is a string? -Rob On Jan 19, 2009, at 8:16 PM, Simon Tan wrote: > haha actually, the other way around :) I have a string(I > believe...I'm > using Hpricot to retreive web pages and it likes to add slashes to > everything). For example, I want to change "Hello, \nWorld" by > changing > \n into a newline. So the output should be like: > Hello > World > > > I did try your suggestion, but I get "Hello\\nWorld". Will keep > playing > with the slashes. > > Rob Biedenharn wrote: >> On Jan 19, 2009, at 7:19 PM, Simon Tan wrote: >> >>> -- >> Are you trying to turn this: >> >> Hello, >> World >> >> Into something like: >> >> Hello,\nWorld >> >> If so, you need to change "\n" (1 character string) into "\\\\n" (3 >> character string, two escaped backslashs and the letter 'n'). The >> replacement string will undergo two different interpretations: as a >> string literal "\\\\n" becomes \\n which when interpreted as a >> replacement for a regexp undergoes another round (so that things like >> \1 and \2 can reference groups in the regexp) and becomes \n >> >> Yes, this is tricky, but it's because there are two levels of >> escaping >> going on and both use the backslash. >> >> -Rob >> >> Rob Biedenharn http://agileconsultingllc.com >> Rob@AgileConsultingLLC.com > > -- > Posted via http://www.ruby-forum.com/. > Rob Biedenharn http://agileconsultingllc.com Rob@AgileConsultingLLC.com +1 513-295-4739 Skype: rob.biedenharn