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?