I want to replace the "/" into "\/" using javascript.
for example:
http://www.freeformatter.com/javascript-escape.html
to
http:\/\/www.freeformatter.com\/javascript-escape.html
I want to replace the "/" into "\/" using javascript.
for example:
http://www.freeformatter.com/javascript-escape.html
to
http:\/\/www.freeformatter.com\/javascript-escape.html
You can do:
str.replace(/\//g, "\\/");
where str is the variable that holds the string value.
use replace:
"http:/www.freeformatter.com/javascript-escape.html".replace(/\//g, "\\/");
If you have the string in a variable:
var url = "http:/www.freeformatter.com/javascript-escape.html";
url.replace(/\//g, "\\/");
You could use str.replace() and a Regular expression object here. Basically you just need to escape the escape character in your replacement string.
str = str.replace(new RegExp('/','g'),"\\/");