// malformed string
var str = "C:\Windows\Fonts";
// C:WindowsFonts
alert(str.replace(/\\/g, "/"));
How do I correctly replace \
with /
so I can get C:/Windows/Fonts
?
// malformed string
var str = "C:\Windows\Fonts";
// C:WindowsFonts
alert(str.replace(/\\/g, "/"));
How do I correctly replace \
with /
so I can get C:/Windows/Fonts
?
Because it is special character use escape mark
var str = "C:\\Windows\\Fonts";
You need to add one more backslash to show the special character.
var str = "C:\\Windows\\Fonts";
alert(str);
Whenever you use the special character in JAvascript you need to add one backslash.