0

I currently have the following string with me

var docPath="\\\\Server\Users\Files\Order\file1.pdf"

Where in I need to replace the single backslashes to two back slashes in my ionic 3 mobile application

like this var docPath="\\\\Server\\Users\\Files\\Order\\file1.pdf"

This is what Ive tried so far

docPath=docPath.replace('\\', "\\\\")

which doesn't change anything.

Codebadger
  • 35
  • 5
  • 1
    Possible duplicate of [Replace single backslash "\" with double backslashes "\\"](https://stackoverflow.com/questions/16144090/replace-single-backslash-with-double-backslashes) – DNKROZ Jun 21 '18 at 10:31

2 Answers2

1

The slash character is interpreted as the start of an escape sequence when the JavaScript parser parses the JavaScript source code.

By the time you try to apply your replace call to the string, the slashes have already been converted into what their escape sequences represent.

You are too late!


You have to fix the source code. You can't recover the data after the JavaScript parser has destroyed it.

var docPath="\\\\Server\\Users\\Files\\Order\\file1.pdf"
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
0

I think your error is already at

var docPath="\\\\Server\Users\Files\Order\file1.pdf". 

I think

var docPath="\\\\Server\\Users\\Files\\Order\\file1.pdf" 

would be correct

Pete
  • 81
  • 1
  • 8