Re: [Flashcoders] Reliable way to split a string into an array of lines?

2007-09-14 Thread jtgxbass
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

Re: [Flashcoders] Reliable way to split a string into an array of lines?

2007-09-13 Thread Mark Winterhalder
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" ); }

Re: [Flashcoders] Reliable way to split a string into an array of lines?

2007-09-13 Thread keith
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 --

Re: [Flashcoders] Reliable way to split a string into an array of lines?

2007-09-13 Thread Andy Herrman
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

[Flashcoders] Reliable way to split a string into an array of lines?

2007-09-12 Thread Danny Kodicek
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