Recursive search and replace in AS2 (actionScript 2)

After searching for a function that searches for all occurrences of a string within a body of text and replaces it with another string, I decided to write my own so here it is:

function replace (search, replace, subject):String {
r = subject.split(search).join(replace);
if (r.indexOf(search) == -1) {
return r;
} else {
replace(search, replace, r);

Leave a Reply