PDA

View Full Version : [AS3] How do I remove the linebreak character from string from an input textArea?


jenniferma
03-06-2009, 10:49 AM
How do I remove the line break(or newline) character from string read in from an input textArea?
Say I have a TextArea and input some text with line breaks.
So when I get the input text from TextArea and stores it in a String, how do I get rid of the invisible new line character?
Actually, I want to replace each new line character with <br>
The character set \n seems not working in my regular expression which it can not be found in the string.
How can I do that? What goes in the regular expression?
Here's my bit of code:
//I have a textArea instance named inputText
inputText.addEventListener(Event.CHANGE, getString);
var pattern:RegExp = /what is the code for newline character/gi;
var s:String;

function getString(e:Event):void {
s = inputText.text;
s = s.replace(pattern, "<br>");
}

rawmantick
03-06-2009, 10:57 AM
string = string.split("\r").join("");

Well probably something more with regexp, that I don't know for a while (shame on mey...)

jenniferma
03-06-2009, 11:04 AM
It worked! Thank you!