barra inclinada hacia atrás a barra inclinada usando javascript

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

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

a:

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.

preguntado el 24 de agosto de 12 a las 08:08

3 Respuestas

El primero debería ser var p = "D:\\upload\\date\\csv\\sample.csv";

Un único \ 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, '/');

Respondido 24 ago 12, 08:08

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

Respondido 24 ago 12, 08:08

además,

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

Respondido 24 ago 12, 08:08

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.