Path with backslashes to path with forward slashes javascript

匆匆过客 提交于 2019-12-04 00:11:10

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/13608564/path-with-backslashes-to-path-with-forward-slashes-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!