I would like to replace multiple words from below string:
\njava developer\n
How do I replace \n from start and \n from last from above string? I used
replace('\n', '')
but it replace first \n only.
I would like to replace multiple words from below string:
\njava developer\n
How do I replace \n from start and \n from last from above string? I used
replace('\n', '')
but it replace first \n only.
If you want to replace all \n
without calling replace in a loop you have to use a regular expression. You can use it like this:
var test = "\njava developer\n";
var result = test.replace(/\n/g, '');
the g
in the regular expression means replace all occurrences.
Hope this helps.
Thanks vincent! It works for me. I implement like this
stringToChange.toLowerCase().toString().replace(/[<b></b>\n]/g,'')
to replace
<\b>, <b> and \n
all multiple occurrences.