PDA

View Full Version : String.replace()



trundrumbalind
March 19th, 2008, 02:29 AM
Hi guys,
Ok I have an input text field with htmlText set to false.
Now, I want to grab data from the text field but I want to convert line breaks to "<br />". I used this code...

textDescription.text.replace("\r", "<br />");
Which works fine for the first line break but any breaks after that aren't replaced. Any ideas?

amarghosh
March 19th, 2008, 03:27 AM
check this:
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/String.html#replace( (http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/String.html#replace%28))

String.replace() method Matches the specified pattern against the string and returns a new string in which the first match of pattern is replaced with the content specified by repl.

trundrumbalind
March 19th, 2008, 08:17 AM
Just to let anyone else with this problem know, I just wrapped the above code with a "while (textDescription.text.indexOf("<br />") != -1)" loop...