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.

see here more info


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -