Wednesday, December 1, 2010

javascript string replace all?

Javascript String "replace" function only replace 1 instance of the string.
If you need a replaceAll function, here is a handy function:

function replaceAll(source, find, replace) {
if (source == null) { return source; }
var aString = source.split(find);
return aString.join(replace);
}

No comments: