带有反斜杠的路径到带有正斜杠的路径javascript [英] Path with backslashes to path with forward slashes javascript

查看:46
本文介绍了带有反斜杠的路径到带有正斜杠的路径javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为某些同事制作一个本地 xml文件解析应用程序",并且我正在使用当前函数来检索文件:

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?

我尝试了replace方法:

I tried the replace method:

pathString.replace(/\\/g, "/")

但是似乎并不能解决问题.

But it doesn't seem to do the trick.

你们能帮我吗?

推荐答案

replace 方法不会更改字符串的当前实例,但会返回一个新的字符串.看看是否可行:

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,"/");

请参见关于jsfiddle的示例.

这篇关于带有反斜杠的路径到带有正斜杠的路径javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆