String ReplaceAll with Flex and Actionscript

0 comments

Posted on 14th June 2010 by Brian Coleman in Actionscript | Flex

, , , ,

This is one of those standards you keep coming back to.
Using RegEx is the quickest way to replace all string values, using the /g flag to make the replace work for all instances in the string.
For something simple you’d do this

myString = myString.replace(/text to find/g, “replace text with this”);

but if there’s any special characters, remember to escape them

myString = myString.replace(/\[text to find\]/g, “replace text with this”);

No comments yet.

Leave a comment

Anti-Spam Protection by WP-SpamFree