Forum Moderators: open

Message Too Old, No Replies

split string value by carriage return

         

SillyWilly

7:49 pm on Jul 17, 2009 (gmt 0)

10+ Year Member



I get the string from a p element and I want to split it by carriage returns. I'm only having trouble so far, with splitting by carriage returns.

splitByCarriageReturns = myString.split(/\r/)

I've tried \n in the RegExp

I've tried fromCharCode(10) & fromCharCode(13)

Fotiman

8:10 pm on Jul 17, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Welcome to WebmasterWorld!
If you're getting the string from a <p> element, then you won't be able to split it by the carriage returns, at least not for IE. Firefox, Chrome, etc. will create multiple TEXT_NODE child nodes of the <p> element for each line, but IE throws away those newlines and gives you just a single TEXT_NODE.

Note, I believe the syntax you would have used (if you had a string that contained newlines, not just carriage returns) would have been:

splitByNewLines = myString.split("\n");

This doesn't solve your problem though.

SillyWilly

9:44 pm on Jul 17, 2009 (gmt 0)

10+ Year Member



That's fine. I don't need a cross-browser solution.

I'm just wanting to create a program for myself and so I don't care what browser I have to use.

I think I know how to do it now. Thanks a lot.

If I can't get it to work then I'll reply back here.

Thanks for the welcome. :)

I've been wanting to join here for a long time but I finally quit being lazy and called my ISP to get my email from them so I could sign up here.