是否可以将“\t”与“\t”分开?到 char '\' + 't'

发布于 2024-12-08 12:29:40 字数 398 浏览 1 评论 0原文

我有包含 Windows 文件路径的字符串。它看起来像这样:

var path = 'c:\test\old\new\ring.txt';

操作系统和浏览器把它给了我。所以我无法通过在每个“\”前面手动写入“\”来更改它。每个 '\' 只是 '\,' 常规获胜路径分隔符。如果“\”后面跟着 t、r、n,就会出现问题。

然后它就变成了空白。但是,如果我将其作为函数参数传递,字符串会自动更改,所有 \ 都会消失!

那么,有没有办法以某种方式将 '\t' '\n' '\r'... 与 '\' + char 分开?

如果不是,是否有可能以某种方式转义 '\' 以便它们保留 '\'?像 \ 并且不要成为制表符、换行符等

编辑: 也许是我表达得不够清楚。

I have got string containing windows path to file. It looks something like this:

var path = 'c:\test\old\new\ring.txt';

Os and browser gave it to me. So I can not change it by manually writing '\' in front of every '\'. Every '\' is just '\,' regular win path delimiter. Problem arises if '\' is followed by t, r, n.

Then it becomes white space. But if I pass that as function parameter string is automatically changed in way that all \ are gone!

So, is there a way to somehow separate '\t' '\n' '\r'... to '\' + char?

If not, is is possible to somehow escape '\' so that they remain '\'? Like \ and not to become tab, new line, etc

edit:
Maybe I wasn't clear enough.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

坦然微笑 2024-12-15 12:29:40

通过加倍反斜杠来转义:c:\\test\\etc

Escape the backslash by doubling it: c:\\test\\etc.

尤怨 2024-12-15 12:29:40
var path = 'c:\\test\\old\\new\\ring.txt';
var path = 'c:\\test\\old\\new\\ring.txt';
混吃等死 2024-12-15 12:29:40

反斜杠转义字符,因此您要转义 t、n、o 和 r。您需要转义反斜杠。你可以这样做:

var path = 'c:\\test\\old\\new\\ring.txt'; 

The backslash is the escape character, so you are escaping the t, n, o, and r. You need to escape the backslash. You can do that like this:

var path = 'c:\\test\\old\\new\\ring.txt'; 
不即不离 2024-12-15 12:29:40

如果确实需要使用反斜杠,请将其转义:'C:\\whatever'

如果确实要使用路径:使用正斜杠。虽然 Windows 显示反斜杠,但它也接受正斜杠。

If you really need to use backslashes, escape them: 'C:\\whatever'

If the path is actually meant to be used: Use forward slashes. While windows displays backslashes, it accepts forward slashes, too.

笑叹一世浮沉 2024-12-15 12:29:40

抱歉,这是我的错误。
操作系统已经给了我转义的反斜杠“\”路径!
我从 mu 函数中得到了未定义,因为 this 指向 html 对象而不是带有函数的 js 对象。

我的错:(

Sorry, it was my mistake.
OS already gave me escaped backslashes '\' path!
I was getting undefined from mu function because of this pointing to html object and not js object with function.

My bad :(

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文