string - backward slash to forward slash using javascript - Stack Overflow

I want to replace "" with "" in a javascript string.var p = "D:uploaddate

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 badges
Add a ment  | 

3 Answers 3

Reset to default 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, '/');

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条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信