0

Variable fileLocation may get two kinds of strings

  1. "N:\LDWG\PDF\2002P48.pdf"

  2. "\\Gis1\GIS\LDWG\Pdf\2007P69.pdf"

I just want result to be like

"N:/LDWG/PDF/2002P48.pdf"

"//Gis1/GIS/LDWG/Pdf/2007P69.pdf"

respectively

Tried

fileLocation.replace(/\\/g,"/")

str.replace("\\", "/")

But didn't work.

Note: There is a double slash in 2nd string

12
  • You must have double slashes in the strings, e.g.: var s = "N:\\LDWG\\PDF\\2002P48.pdf". Then, the string will look like N:\LDWG\PDF\2002P48.pdf. Your fileLocation = fileLocation.replace(/\\/g,"/") will work. Commented Feb 3, 2016 at 13:01
  • fileLocation.replace(/\\+/g,"/") Commented Feb 3, 2016 at 13:02
  • Yeah, people were advising in other SO questions. But I don't how to do that, the data comes in that way. And also I wonder if it works for string, type 2 too Commented Feb 3, 2016 at 13:03
  • You need to assign the value to the variable fileLocation = fileLocation.replace(/\\/g,"/") Commented Feb 3, 2016 at 13:04
  • @Jai, It didn't work. Have a look at this jsFiddle Commented Feb 3, 2016 at 13:11

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.