C# 标签转义字符?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5787/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-07-31 16:25:06  来源:igfitidea点击:

Tab Escape Character?

提问by GateKiller

I'm just in the process of parsing some text and can't remember what the escape character is for a tab in C#?

我正在解析一些文本,不记得 C# 中选项卡的转义字符是什么?

采纳答案by Matt Hamilton

Easy one! "\t"

轻松一个!“\t”

Edit: In fact, here's something official: Escape Sequences

编辑:事实上,这是官方的:转义序列

回答by andrew.fox

For someone who needs quick reference of C# Escape Sequencesthat can be used in stringliterals:

对于需要快速参考可用于文字的C# 转义序列的人string

\t     Horizontal tab (ASCII code value: 9)

\n     Line feed (ASCII code value: 10)

\r     Carriage return (ASCII code value: 13)

\'     Single quotation mark

\"     Double quotation mark

\\     Backslash

\?     Literal question mark

\x12     ASCII character in hexadecimal notation (e.g. for 0x12)

\x1234     Unicode character in hexadecimal notation (e.g. for 0x1234)

\t 水平制表符(ASCII 码值:9)

\n 换行(ASCII 码值:10)

\r 回车(ASCII 码值:13)

\' 单引号

\" 双引号

\\ 反斜杠

\? 字面问号

\x12 十六进制表示法的 ASCII 字符(例如 0x12)

\x1234 十六进制表示的 Unicode 字符(例如 0x1234)

It's worth mentioning that these (in most cases) are universal codes. So \t is 9 and \n is 10 char value on Windows and Linux. But newline sequence is not universal. On Windows it's \n\r and on Linux it's just \n. That's why it's best to use Environment.Newlinewhich gets adjusted to current OS settings. With .Net Core it gets really important.

值得一提的是,这些(在大多数情况下)是通用代码。所以在 Windows 和 Linux 上 \t 是 9 并且 \n 是 10 个字符值。但是换行序列不是通用的。在 Windows 上它是 \n\r 而在 Linux 上它只是 \n。这就是为什么最好使用Environment.Newline根据当前操作系统设置进行调整的原因。使用 .Net Core,它变得非常重要。