I have a string that is passed by parameter and I have to replace all occurrences of it in another string, ex:
function r(text, oldChar, newChar)
{
return text.replace(oldChar, newChar); // , "g")
}
The characters passed could be any character, including ^, |, $, [, ], (, )...
Is there a method to replace, for example, all ^ from the string I ^like^ potatoes with $?
String.prototype.replaceonly replaces the first occurrence of strings; you need to use a regular expression with theglobal flag if you want global replacement.