1

I need replace a character in a string for a backslash,

example

var string = "hello world!"; string.replace("!","\");

help me please

thanks!!!!

1
  • 1
    string.replace("!","\\"); Commented Feb 1, 2016 at 21:43

1 Answer 1

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 !

Sign up to request clarification or add additional context in comments.

2 Comments

I'm pretty sure that's a dupe, but haven't found the proper dupe ;)
Probably yes as dup finding isn't very easy here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.