Tammo Tjarks
1/20/2009 7:46:00 AM
Simon Tan wrote:
If you want to substitute
Hello\nWorld by
Hello
World
you should try to work with single quotes:
a = 'Hello\nWorld'
Simon Tan wrote:
=> "Hello\\nWorld"
irb(main):002:0> puts a
Hello\nWorld
=> nil
irb(main):003:0> a.gsub!('\n',"\n")
=> "Hello\nWorld"
irb(main):004:0> puts a
Hello
World
> Hi all, I'm not sure why but I assumed gsub! would allow me to replace
> \n with line feeds or \r for carriage returns.
>
> How do I gsub! and replace everything with a nonvisible character like
> newline? I was using this results.gsub!("\n","\n") but obviously that
> does not work :( also tried results.gsub!("\n",10.chr). No go.
>
> Kinda of frustrating for something so simple. I guess I could always do
> some recursion. Thanks.