I'm looking for a function that does replaceAll with any start and endcharacter.
I know I can use the regex notation:
string=string.replace(/a/g,"b");
However, because the searched char is in a regex, I sometimes need to escape that character and sometimes not, which is annoying if I want to do this for a full list of chars
convertEncoding= function(string) {
var charMap= {'"':""",'&':"&",...}
for (startChar in charMap) {
endChar=charMap[startChar];
string= string.replaceAll(startChar,endChar);
}
}
Is they a good way to write that function replaceAll, without doing a for loop and using String.replace()
(eg the naive way) ?