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.
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, '/');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With