How to replace a hypen (-) with a slash (\) in Javascript?
for example, I need to replace
C-MyDocuments-VisualStudio2008-MyProjects
with
C\MyDocuments\VisualStudio2008\MyProjects
I tried replace function such as variable.replace("-","\") but it showed me error of unterminated string constant.
I am working in VS 2008.
You need to escape the slash with an additional backslash like this:
To replace the hyphen globally, try this:
This uses a regular expression to search the string for the hyphen and the
gmodifier indicates that replacements should be global.