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.
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.
Share Improve this question asked Aug 24, 2012 at 7:46 AneeshAneesh 1,2033 gold badges17 silver badges26 bronze badges3 Answers
Reset to default 3The 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, '/');
var p = 'D:\\upload\\date\\csv\\sample.csv';
p = p.replace(/\\/g, '/');
also
p=p.split("\\").join("/");
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745107893a4611666.html
评论列表(0条)