replaceall in javascript example
ReplaceAll method in java script.
function ReplaceAll(content,findWith,replaceWith){
var str = content;
var index = str.indexOf(findWith);
while(index != -1){
str = str.replace(findWith,replaceWith);
index = str.indexOf(findWith);
}
return str;
}
function ReplaceAll(content,findWith,replaceWith){
var str = content;
var index = str.indexOf(findWith);
while(index != -1){
str = str.replace(findWith,replaceWith);
index = str.indexOf(findWith);
}
return str;
}
alert(ReplaceAll("shit","s","s"));
ReplyDeleteCORRECT:
ReplyDeletefunction ReplaceAll(content,findWith,replaceWith){
var str="";
if ( findWith != replaceWith ) {
var flen=findWith.length;
var index=content.indexOf(findWith);
while ( index != -1 ) {
str+=content.substr(0,index)+replaceWith;
content=content.substr(index+flen);
index = content.indexOf(findWith);
}
}
return str;
}
alert(ReplaceAll("fefe","e","ee"));
Thanks for the helps.... is very good.
ReplyDelete