Extended Replace function
Works like Replace() in VB.
function massReplace(token, findThis, replaceWithThis) {
replaceHash = token.toString();
thisIndex = replaceHash.indexOf(findThis);
while(thisIndex !=- 1) {
replaceHash = replaceHash.replace(findThis, replaceWithThis);
thisIndex = replaceHash.indexOf(findThis);
}
return replaceHash;
}
To use it simply specify. Input parameters are token (the raw string you want to use), FindThis (pretty simple), and ReplaceWithThis (self explanatory). An example would look like this:
alert(massReplace(’johnny made his dog do his homework. His dog did well.’,'dog’,'computer’));
See the output
The only catch to it is that while VB is not case sensitive, Javascript is. So this function will not work exactly like the VB replace() function without additional case handling. I’m actually working on another function to do that sort of case handling, but has not had the time to finish it. Check back later, and it will be posted on the home page.
You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.

