In my html page I have to split user input based on newline character. How to get newline character using javascript?
Asked
Active
Viewed 112 times
-1
-
possible duplicate of [JavaScript string newline character?](http://stackoverflow.com/questions/1155678/javascript-string-newline-character) – Jordi Castilla Feb 25 '15 at 11:34
-
sorry i dont get you properly....can you explain....? – sathishrtskumar Feb 25 '15 at 11:48
-
check the question linked to find existing answer ;) – Jordi Castilla Feb 25 '15 at 11:53
2 Answers
0
The resume of possible duplicate is using regex
does allow you to ignore the OS
you're using:
I don't think you really need to do much of any determining, though. If you just want to split the text on newlines, you could do something like this:
lines = foo.value.split(/\r\n|\r|\n/g);
In your case:
var splittedValues = originalTxt.split(/\r\n|\r|\n/g);

Community
- 1
- 1

Jordi Castilla
- 26,609
- 8
- 70
- 109
-
i did same splitting in java...but it was working in my local system and not working in live...because linux new line character is different from windows... thats why i tried to get new line char and split based on that... Thanks.... – sathishrtskumar Feb 25 '15 at 12:00
-
-
my code is working in windows but not working in linux system var splittedValues = originalTxt.split('\n'); – sathishrtskumar Feb 25 '15 at 12:08
-
your code is not correct, please, **read the answers and the duplicate question**.... – Jordi Castilla Feb 25 '15 at 12:10
0
Please see the below code :
var str=document.getElementById('nwline').value;
var lines = str.split(/\r\n|\r|\n/g);
console.log(lines);

asimshahiddIT
- 330
- 2
- 5
-
1i am not sure javascript newline character is \n in all Operating System...thats why i asked... – sathishrtskumar Feb 25 '15 at 12:03