Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
78 views
in Technique[技术] by (71.8m points)

Replace function `` error in the javascript

I have a problem with the string symbol error, I want replace this symbol , but it doesn't work. My sample code javascript like below the coding:

I am doing below this testing, cannot alert the message

var file_name = "C:fakepathclaim 20210121 1754.sql";
var bbb = file_name.replace("C:fakepath", "123");
alert(bbb);
question from:https://stackoverflow.com/questions/65839379/replace-function-error-in-the-javascript

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

1 Answer

0 votes
by (71.8m points)

Backslash begins escape sequences, you need to double them to make them literal.

var file_name = "C:\fakepath\claim 20210121 1754.sql";
var bbb = file_name.replace("C:\fakepath", "123");
alert(bbb);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...