first_page the funky knowledge base
personal notes from way, _way_ back and maybe today

ActionScript: “TextField.text Gotcha: \\n becomes \\r” by Colin Moock

TextField.text Gotcha: \\n becomes \\r

Here's a little TextField quirk: when you assign the string "\\n" (newline) to a TextField's text variable, ActionScript automatically converts it to a "\\r" character. For example,

var t:TextField = new TextField() t.text = "Hello\\nworld";

trace(t.text.indexOf("\\r")); // 5 trace(t.text.indexOf("\\n")); // -1

So if you're hunting for a "\\n" you've added to a text field, you'll need to search for "\\r", not "\\n". The docs for TextField's text variable actually point out that "\\r" is used:

"Lines are separated by the carriage return character ('\\r', ASCII 13)."

But the docs fail to mention that "\\n" is converted to "\\r".

[http://www.moock.org/blog/archives/000281.html]

mod date: 2009-07-31T21:05:35.000Z