regex - How can I remove the string "\n" from within a Ruby string? -
i have string:
"some text\nandsomemore"
i need remove "\n" it. i've tried
"some text\nandsomemore".gsub('\n','')
but doesn't work. how do it? reading.
you need use "\n"
not '\n'
in gsub. different quote marks behave differently.
double quotes "
allow character expansion , expression interpolation ie. let use escaped control chars \n
represent true value, in case, newline, , allow use of #{expression}
can weave variables and, well, pretty ruby expression text.
while on other hand, single quotes '
treat string literally, there's no expansion, replacement, interpolation or have you.
in particular case, it's better use either .delete
or .tr
string method delete newlines.
Comments
Post a Comment