views:

2585

answers:

1

I have a textfield where the user can type what ever he want into it. When the user is ready typing he can hit the send button. when he does that i get the text from the multiline textfield and pass it to my backend. there is only 1 problem the text is formated in 1 single line, (html text is no option!) is it possible to set after every line a \n character?

A: 
var st : String ="";
for (var i:int = 0; i < tf.numLines; i++) {

            var s:String = tf.getLineText(i) + "\n";
            st += s;
}

does the trick

Andy Jacobs
It properly does not mather much in this case, but you should not append to a string. It creates a new string every time. It much faster and less memory intensiv to add the strings to an array and then join them afterwards with the Array.join() method.
Lillemanden
You might want to look at TextField.appendText as well
PiPeep