I find this fast and reliable...
var lines:Array = str.split
("\r\n").join("\n").split("\r").join("\n").split("\n");
On 9/13/07, Mark Winterhalder <[EMAIL PROTECTED]> wrote:
>
> var lines : Array = (str.indexOf( "\r\n" ) > -1) ? str.split( "\r\n" )
> : str.split( "\n" );
>
> Or, if you want to t
var lines : Array = (str.indexOf( "\r\n" ) > -1) ? str.split( "\r\n" )
: str.split( "\n" );
Or, if you want to take MacOS 9 into account:
var lines : Array;
if( str.indexOf( "\r\n" ) > -1 ) {
lines = str.indexOf( "\r\n" );
} else if( str.indexOf( "\n" ) > -1 ) {
lines = str.split( "\n" );
}
If you have the libertry to go the RegExp, it's much easier.
(Put everything you consider a linebreak in the brackets with [\r\n\f\v]
var lines:Array=myStr.replace(/[\r\n\f\v]/mig,"\n").split("\n");
trace(lines.length.toString());
Don't know if that's what you was talking about.
-- Keith H --
The fastest (execution, not writing) way would probably be to do your
own loop over the string and find all the positions of line breaks
(either \r or \n) and use just use substring to pull out the
individual lines.
If you do end up trying RegExes I'd be very interested in how you do
it. The only
I'm looking for a simple, reliable method for splitting a string into its
constituent lines (at the hard line breaks - this isn't a text wrapping
thing). The problem is that line breaks could be Chr(10) or Chr(13), or
indeed both. I've done this:
myArr =
myStr.split(String.fromCharCode(10)).join(S
5 matches
Mail list logo