I was trying to split a string on a newline character today and having some issues. The string was a text node loaded from an xml file, and i could see that the line breaks were coming in intact. However when i tried to split the string on the “\n” character, it wouldn’t work. Long story short, internally flash represents a newline character as “\r”, so string.split(”\r”) works fine.
FlashApe » Newlines in xml
Newlines in xml
- July 10th, 2007
- 11:25 am
2 People had this to say...
- Zach
- October 14th, 2007
- 10:38 pm
Thanks! You just saved me several minutes of grief…
That’s certainly one thing that I wish was more consistent across systems. In Javascript, I am pretty sure the line break is \n, not \r. On Windows machines, I think they use \r\n. On *nix machines I think they use just \n. In ColdFusion, GetToken() won’t use both \r and \n as a token delimiter, just one (but I can’t remember which one, I think \n).
Anyhow, it’s frustrating and I wish it was more consistent.