Replacing can also be done with a simple loop.
Here's a function I made that replaces the default String.replace function. I haven't tested it thoroughly, but I'm sure the bugs are nothing complicated
To use it, use the normal String.replace function. However, there is an extra parameter. "Count" is an integer, it'll specify how many occurrences to replace in the string. If you leave it out, it will replace all of them.
code:
String.prototype.replace = function(term,replacement,count){
var string = this;
if(count == null){
while(string.indexOf(term) > -1){
string = string.slice(0,string.indexOf(term)) + replacement + string.slice(string.indexOf(term)+term.length,string.length);
}
} else if(typeof count == 'number'){
for(var i = 0; i < count; i++){
string = string.slice(0,string.indexOf(term)) + replacement + string.slice(string.indexOf(term)+term.length,string.length);
}
}
return string;
}