String Replace Function in Flex ActionScript

There is a function String.replace() which returns the result string. But note, this only replaces the first occurance of given string/expression!


So, to actually replace all the occurances of given string/expression, you must loop through until all the matches are replaced. Code & Documentation

However, there is another easy customized function to automatically replace all the occurance of given match. Here goes the customized function:

public function str_replace(mainStr:String, str1:String, str2:String):String
 var temp:Array = mainStr.split(str1);
 var tempStr:String = temp.join(str2);
 return tempStr;


var myStr:String = str_replace("a_b_c", "_" , "1");   // a1b1c1

Got Help From Source

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s