C# 支持哪些转义序列?

来源:这里教程网 时间:2026-02-21 16:23:45 作者:

c# 支持哪些转义序列?

以下示例展示了如何在 C# 中显示一些转义字符 -

示例

using System;
using System.Collections.Generic;
class Demo {
   static void Main() {
      Console.WriteLine("Warning!" + '\u0007');
      Console.WriteLine("Test \t Demo Text");
      Console.WriteLine("This is it!This is on the next line!");
   }
}

对于C#中的转义序列的完整列表 −

转义字符 描述 模式
\a 匹配响铃字符,\u0007。 \a
\b 在字符类中,匹配退格字符,\u0008。 [\b]{3,}
\t 匹配制表符,\u0009。 (\w+)\t
\r 匹配回车符,\u000D。(\r与换行符不等价,

\r

(\w+)

\v 匹配垂直制表符,\u000B。 [\v]{2,}
\f 匹配换页符,\u000C。 [\f]{2,}
匹配换行符,\u000A。 \r

(\w+)

\e 匹配转义符,\u001B。 \e

相关推荐