January 03, 2011

replacing line breaks in actionscript

here's a quick code snippet to replace windows-style line breaks (CRLF, or carriage return, line feed) with a standard actionscript new line character.

var newText:String = oldText.replace(/\r\n/g, "\n");

and here's a snippet to replace all multiple line breaks with a single new line character:

var newText:String = oldText.replace(/[\r\n]+/g, "\n");

for example, the preceding code would change the following string:

a


b

to this:

a
b

Posted by moock at 06:03 PM | Comments (0)