I have this string:
"some text
andsomemore"
I need to remove the " " from it. I've tried
"some text
andsomemore".gsub('
','')
but it doesn't work. How do I do it? Thanks for reading.
See Question&Answers more detail:osI have this string:
"some text
andsomemore"
I need to remove the " " from it. I've tried
"some text
andsomemore".gsub('
','')
but it doesn't work. How do I do it? Thanks for reading.
See Question&Answers more detail:osYou need to use "
"
not '
'
in your gsub. The different quote marks behave differently.
Double quotes "
allow character expansion and expression interpolation ie. they let you use escaped control chars like
to represent their true value, in this case, newline, and allow the use of #{expression}
so you can weave variables and, well, pretty much any ruby expression you like into the text.
While on the other hand, single quotes '
treat the string literally, so there's no expansion, replacement, interpolation or what have you.
In this particular case, it's better to use either the .delete
or .tr
String method to delete the newlines.