[英]Javascript substring with escape characters
i have a string like the following 我有一个像下面这样的字符串
var string1 = " folder\\subfolder1\\subfolder2 "
and i want to replace the "\\" with "/" with string1.replace in order to be 我想用string1.replace替换“/”和“/”
var string2 = "folder/subfolder1/subfolder2"
I tried 我试过了
var rep = path.replace("\\", "/");
but is not working. 但是没有用。 Any help ?
有帮助吗?
你需要全局地做,例如使用regexp文字和g
标志;
var rep = path.replace(/\\/g, "/");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.