Posted By

arpo on 09/04/09


Versions (?)

Fix text line end problem. Remove Double blank lines

 / Published in: ActionScript 3

\n = linux \r = mac (prior to macos being based on freebsd I guess) \r\n = the damned pc linefeed.

The TextField object in Flash seems to render both \r and \n as linefeeds. Therefore I was getting way too many linefeeds in my rendered text.

Tada! _text is of type String. The /g is VERY important at the end of the declaration of the RegExp, it means it will replace ALL instances. If you do not put /g it wont.

  1. var pcLB:RegExp = /
  2. /g;
  3. var macLB:RegExp = /\r/g;
  4. var linuxLB:RegExp = /\n/g;
  5. text = _text.replace(pcLB, "\n");
  6. text = _text.replace(macLB, "\n");

Report this snippet  


RSS Icon Subscribe to comments
Posted By: knalle on September 11, 2009

an old scholl way of doing it could be something like this:

myString= myString.split("\r\n").join("\n");

Dunno if it's slower?

Posted By: arpo on November 6, 2009

This is more fancy ;)

You need to login to post a comment.