Answer by jValdron for How to replace all characters in a string?
If you simply pass '^' to the JavaScript replace function it should be treated as a string and not as a regular expression. However, using this method, it will only replace the first character. A...
View ArticleAnswer by aefxx for How to replace all characters in a string?
function r(t, o, n) { return t.split(o).join(n);}
View ArticleAnswer by Elias Dorneles for How to replace all characters in a string?
Use a RegExp object instead of a simple string:text.replace(new RegExp(oldChar, 'g'), newChar);
View ArticleHow to replace all characters in a string?
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...
View Article