Reputation: 1203
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.
Upvotes: 3
Views: 7676
Reputation: 54659
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, '/');
Upvotes: 3
Reputation: 10470
var p = 'D:\\upload\\date\\csv\\sample.csv';
p = p.replace(/\\/g, '/');
Upvotes: 0