Tag Archives: as3 strreplace

strReplace in ActionScript

function strReplace(str:String, search:String, replace:String):String {
return str.split(search).join(replace);
Description: A function used for replacing portions of a string with a new one. Note that this function does not modify the original string.

str:String – The string to have portions replaced.
search:String – The string to search for and replace in str.
replace:String – The string which is placed where the search string is found.

String – The original string with portions replaced.

Example Usage:

var str:String = “Hello World!”;
trace(strReplace(str, “Hello”, “Goodbye”)); //outputs Goodbye World!
trace(str); //outputs Hello World!