@(AT)的文件路径标志/串 [英] @(at) sign in file path/string

查看:137
本文介绍了@(AT)的文件路径标志/串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
  什么是在.NET中字符串前面的@?

我有以下的code:

new Attachment(Request.PhysicalApplicationPath + @"pdf\" + pdfItem.Value)

什么是 @ 标志呢?

推荐答案

它无关的文件路径。它改变琴弦的逃逸行为。

It has nothing to do with filepath. It changes the escaping behavior of strings.

在与一个字符串$ P $ @ pfixed 的转义序列开始 \\ 被禁用。这是方便,因为文件路径 \\ 是路径分隔符,你不希望它启动一个转义序列。

In a string literal prefixed with @ the escape sequences starting with \ are disabled. This is convenient for filepaths since \ is the path separator and you don't want it to start an escape sequence.

在一个正常的字符串,你将不得不逃离 \\ \\\\ 让你的例子看起来像这样 PDF \\\\。但是,由于它与 pfixed @ $ P $需要逃逸的唯一字符是(被转义为)和 \\ 可以简单地出现。

In a normal string you would have to escape \ into \\ so your example would look like this "pdf\\". But since it's prefixed with @ the only character that needs escaping is " (which is escaped as "") and the \ can simply appear.

此功能方便了含有字符串的文字 \\ 如文件路径或正则表达式。

This feature is convenient for strings literals containing \ such as filepaths or regexes.

有关您简单的例子增益不那么大,但是像你有一个完整的路径C:\\\\ ABC \\\\ \\\\ CDE DEF然后 @C:\\ ABC \\ CDE \\ DEF。看起来要好很多。

For your simple example the gain isn't that big, but image you have a full path "C:\\ABC\\CDE\\DEF" then @"C:\ABC\CDE\DEF" looks a lot nicer.

有关定期EX pressions这几乎是必须的。一个正则表达式通常包含几个,如果你需要逃避它们 \\ 转义其他字符已经和经常变得几乎无法读取。

For regular expressions it's almost a must. A regex typically contains several \ escaping other characters already and often becomes almost unreadable if you need to escape them.

这篇关于@(AT)的文件路径标志/串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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