Jason Kelly
Jason Kelly

Reputation: 2645

Replacing Backslashes in Javascript

How can I convert the following string from

var x = "F:\RSSIMS\database\"

to:

var x = "F:\\RRSIMS\\database\\"

Thanks for all your help.

Upvotes: 0

Views: 66

Answers (1)

Anirudh Ramanathan
Anirudh Ramanathan

Reputation: 46728

var x = "F:\RSSIMS\database\" is already invalid. You need to escape your backslashes.

var x = "F:\\RSSIMS\\database\\";//stores the string `F:\RSSIMS\database\` in x. 

If you want double-slashes now, do the below to replace all the single slashes by double ones.

x = x.replace(/\\/g,"\\\\");

Upvotes: 5

Related Questions