I want to write JavaScript function strinformat like in c#.
function gg_stringformat(){
argcount=arguments.length;
if (argcount==0) {
return "";
}
else if (argcount==1){
return arguments[0];
}
else {
original =arguments[0];
for (var i=1; i<argcount;i++) {
strtoreplace='{'+(i-1)+'}';
strreplacewith=arguments[i];
original=original.replace('/%' + strtoreplace + '%/gi',strreplacewith);
}//for
return original;
}
}
when I use original=original.replace( strtoreplace , strreplacewith);
it works fine but replaces only first occurence.
with code above it not works at all. what i must do?
gg_stringformatmethod..replace('/%' + strtoreplace + '%/gi', ...)uses one - at least if you fix the error shown in my duplicate. And after that you have to edit the regular expression because right now it would not match the part you want to replace.