Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Newline \n problem in JS

I am reading a file with xmlHttp object and splitting the responseText with newlines by split method.

But "\n" character literally doesn't work. It acts like an error in my code and causes my code not even function. Here is the line:

var lines=myPlaylist.responseText.split("\n");

There is no error if I split the array myPlaylist with other characters. Just \n causes problem which I fail to understand.

At first, I thought the error was due to white-space:nowrap since I execute my code on Chrome. Though I never used white-space in anywhere, I tried to set it to normal but it didn't work. Similarly, I tried my code on other browsers (Firefox, IE etc), it didn't work either. Looks like I have a problem with using \n. Is there any other way to use newline or error with my code?

And by the way, error seems to be a syntax error since it does not just ignore \n character. Simply causes my code not to work

EDIT: An example responseText

[playlist]

File1=http://localhost:7000/Videos/Big%20Buck%20Bunny%20Trailer.ogv
Title1=Bunny Trailer
Length1=23

File2=http://localhost:7000/Videos/Dizzy%20Cat%20Video.ogv
Title2=Kedi 
Length2=33

NumberOfEntries=2

Version=2
like image 967
Oralet Avatar asked Oct 12 '25 11:10

Oralet


2 Answers

I found my own solution to my problem.
After using random special characters, \r character used for carriage return worked like a charm for my problem.
It acted like a newline \n character or at least it did its job in my case.
Thanks everyone for answers and helpful comments.

like image 55
Oralet Avatar answered Oct 14 '25 01:10

Oralet


Try using this line

/\n/

Instead of this one

"\n"
like image 43
Olical Avatar answered Oct 14 '25 00:10

Olical



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!