0

I'm a bit stuck on this issue. I'm trying to make a newline using '\n'. I'm opening a file, then replacing the text, then writing it back as an html file:

replace = text.gsub(/aaa/, 'aaa\nbbb')

But this results in:
aaa\nbbb

I'm trying to make do:
aaa
bbb
oprogfrogo
  • 2,005
  • 5
  • 31
  • 42

2 Answers2

4

In single-quoted strings a backslash is just a backslash (except if it precedes another backslash or a quote). Use double quotes: "aaa\nbbb" .

steenslag
  • 79,051
  • 16
  • 138
  • 171
0

You'll want to read:Backslashes in Single quoted strings vs. Double quoted strings in Ruby?.

Community
  • 1
  • 1
the Tin Man
  • 158,662
  • 42
  • 215
  • 303