开发者

Is it possible to separate "\t" to char '\' + 't'

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 o开发者_如何转开发f 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.


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


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'; 


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.


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 :(

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜