Please login or register. Welcome to the Studio, guest!


Quick Links:


newBookmarkLockedFalling

Moose

Moose Avatar

****
Senior Member

449


August 2005
Nice and simple. Since IE and FF differ in splitting lines as do some others this should be nice and handy.

String.prototype.splitLines = function(){
try {
var linesplit = this.split(/\n/);
} catch(e) {
var linesplit = this.split(/\r\n/);
}
return linesplit;
}

Use as:
var newarray = string.splitLines();

Greg says:
Coding music...
Greg says:
Hmm...
Greg says:
I wouldn't rule it out. :P
Chris 3.0 [New features? Yes.] says:
:P
Greg says:
If you think about machine code it's a bunch of 1s and 0s
Chris 3.0 [New features? Yes.] says:
Anything is possible.
Greg says:
Yeah try to code Metallica
Chris 3.0 [New features? Yes.] says:
:P Yeah, I'll get right on that... right after I learn to fly.

Chris

Chris Avatar

******
Head Coder

19,519


June 2005
I'm not sure the try/catch works with that though. =/ It doesn't return an error.

Moose

Moose Avatar

****
Senior Member

449


August 2005
It does work with try and catch, I tested it. I thought so too at first so I was checking it returned a length greater or a length at all meaning it would be an array. However try and catch was shorter so I gave that a try and actually worked quite nicely.
Greg says:
Coding music...
Greg says:
Hmm...
Greg says:
I wouldn't rule it out. :P
Chris 3.0 [New features? Yes.] says:
:P
Greg says:
If you think about machine code it's a bunch of 1s and 0s
Chris 3.0 [New features? Yes.] says:
Anything is possible.
Greg says:
Yeah try to code Metallica
Chris 3.0 [New features? Yes.] says:
:P Yeah, I'll get right on that... right after I learn to fly.

newBookmarkLockedFalling