3

I want to replace "\" with "/" in a javascript string.

var p = "D:\upload\date\csv\sample.csv";

to:

var p = "D:/upload/date/csv/sample.csv";

But I am getting error in first line itself. "SyntaxError: malformed Unicode character escape sequence".

How to do this ? Please help. Thanks.

3 Answers 3

3

The first one should be var p = "D:\\upload\\date\\csv\\sample.csv";

A single \ is for escaping (or other stuff). In your case the \upload is a problem because \u would indicate an unicode character.

To replace, use: p = p.replace(/\\/g, '/');

Sign up to request clarification or add additional context in comments.

Comments

0
var p = 'D:\\upload\\date\\csv\\sample.csv';
p = p.replace(/\\/g, '/');

Comments

0

also

p=p.split("\\").join("/");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.