是否可以将“\t”与“\t”分开?到 char '\' + 't'
我有包含 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
通过加倍反斜杠来转义:
c:\\test\\etc
。Escape the backslash by doubling it:
c:\\test\\etc
.反斜杠是转义字符,因此您要转义 t、n、o 和 r。您需要转义反斜杠。你可以这样做:
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:
如果确实需要使用反斜杠,请将其转义:
'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.
抱歉,这是我的错误。
操作系统已经给了我转义的反斜杠“\”路径!
我从 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 :(