I'm trying to make a local xml file parsing "application" for some colleagues and i'm using the current function to retrieve the files:
function ShowFolderFileList(folderspec) {
var fso, f, f1, fc, s;
fso = new ActiveXObject("Scripting.FileSystemObject");
f = fso.GetFolder(folderspec);
fc = new Enumerator(f.files);
s = "";
for (; !fc.atEnd(); fc.moveNext()) {
var pathString = fc.item();
$("#test").append(pathString + "<br />");
}
}
The problem with this function it returns a string similar to:
C:\Users\SomeUser\Desktop\cool\Archief\CDATA1.xml
I need to replace the backward slashes to forward slashes of the entire string. How to do this?
I tried the replace method:
pathString.replace(/\\/g, "/")
But it doesn't seem to do the trick.
Can you guys help me out?
As the forward slash (/) is special character in regular expressions, it has to be escaped with a backward slash (\). Also, to replace all the forward slashes on the string, the global modifier (g) is used. It will replace all the forward slashes in the given string.
There are two types of slashes: a backslash (\) and a forward slash (/). The backslash is used only for computer coding. The forward slash, often simply referred to as a slash, is a punctuation mark used in English.
Press \/ to change every backslash to a forward slash, in the current line. Press \\ to change every forward slash to a backslash, in the current line.
The replace
method does not alter the current instance of the string, but returns a new one. See if this works:
pathString = pathString.replace(/\\/g,"/");
See this example on jsfiddle.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With