Skip to content

Split Function in Angular for a certain combination

I have a string which is like this:

  'Hellornand World 15.6n3'.

or it can be

  'Hellornand World 15.6nNA'.

and I want result which should split it like this:

  'Hellornand World 15.6'

The code which I have written:

  var lines = string.split('n');

which is producing result like this:

 'and World 15.6'

What changes should I make in split() function to get the desired result?


You can replace rn with something else, then split by n and put back the replaced rn:

'Hellornand World 15.6n3'.replaceAll('rn', '&newline').split('n').map(item => item.replaceAll('&newline', '\r\n'))