Friday 1 April 2011

JavaScript fuction for ReplaceAll

The solution to replace all using javascript is as follows:
String.prototype.ReplaceAll = function(stringToFind,stringToReplace){

var temp = this;

var index = temp.indexOf(stringToFind);

while(index != -1){

temp = temp.replace(stringToFind,stringToReplace);

index = temp.indexOf(stringToFind);

}

return temp;

}

No comments:

Post a Comment