Welcome to 16892 Developer Community-Open, Learning,Share
menu search
person

Categories

let str ="c:est1"// 变成c:/test/1.txt
console.log(str.replace(//g,"a"));

不知道错哪里了


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
350 views
Welcome To Ask or Share your Answers For Others

1 Answer

let str ="c:est1"

这一句就已经出问题了.里面的单反斜线已经把后面跟的内容转义了..上述输出的结果 c: est
你已经该

let str ="c:\test\1"
console.log(str.replace(/\/g,"/"))

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to 16892 Developer Community-Open, Learning and Share
...