0

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.

Rahul Mankar
  • 910
  • 9
  • 17

2 Answers2

2

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.

Vincent Schöttke
  • 4,416
  • 2
  • 12
  • 12
  • Thanks Vincent! It works for me. I implement like this str.toLowerCase().toString().replace(/[\n]/g,'') to replace , <\b> and \n all multiple occurrences. – Rahul Mankar Aug 13 '16 at 12:07
0

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.

Rahul Mankar
  • 910
  • 9
  • 17