// 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
?
因为是特殊字符使用转义标记
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.