Reputation: 519
I need replace a character in a string for a backslash,
example
var string = "hello world!";
string.replace("!","\");
help me please
thanks!!!!
Upvotes: 1
Views: 56
Reputation: 786091
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 !
Upvotes: 1