Posted by: Vijay Modi | December 25, 2007

Javascript + Replace forward slashes ‘/’ with backward slashes ‘\’.

Hi friends,

Using following Javascript sysntax you can replace forward slashes (‘/’) with backward slashes (‘\’) :

var strReplace = “C:\Temp\Temp1\Temp2\text.jpeg“;

strReplace = strReplace.replace(new RegExp(/\\/g),”/”);

Regardes,

Vijay


Responses

  1. Javascript String Replace Path

  2. Thanks a lot for the valuable solutions.

  3. Nice Code, Thanks a lot

  4. Hi, how would it be shifted, I mean, Replace backward slashes ‘\’ with forward slashes ‘/’.

  5. That is right, your description is wrong, you are replacing \ for /….
    what about the opposite one, how could it be done?

  6. Use this to replace “/” with “\”. The code may not look right depending on your code editor, but it’ll work.

  7. oops, forgot to add the code:
    strReplace = strReplace.replace(/\//g, “\\”);

  8. Here is the code you guys are asking for:
    strReplace = strReplace.replace(/\//g, “\\”);


Leave a response

Your response:

Categories