I need replace a character in a string for a backslash,
example
var string = "hello world!";
string.replace("!","\");
help me please
thanks!!!!
asked Feb 1, 2016 at 21:34
Michael Sanchez
5194 silver badges3 bronze badges
-
1string.replace("!","\\");user557597– user5575972016年02月01日 21:43:19 +00:00Commented Feb 1, 2016 at 21:43
1 Answer 1
You can use:
string = string.replace(/!/g, '\\');
backslash needs to be escaped with another backslash and better to use regex /!/ in order to replace all the occurrences of !
answered Feb 1, 2016 at 21:36
anubhava
791k67 gold badges604 silver badges671 bronze badges
lang-js