Al-Azhar

Archive for the ‘Flash’ Category

A brilliant find and replace snippet

Sunday, September 30th, 2007

I was looking for a way to perform “find and replace” operation on a string in Flash using Actionscript, I googled and came across this, I was really amazed to see how that piece of code does its job.

What it does is simply break the subject string at the occurrences of the needle string and rejoin the resulting array using the replacement string.

function searchAndReplace(holder, searchfor, replacement) {

//Break
temparray = holder.split(searchfor);
//Rejoin
holder = temparray.join(replacement);
//Return
return (holder);
}

Brilliant!

Get Firefox! Valid xHTML 1.1 Valid CSS tracker