C# 中列印跳脫字元的方法
以下是 C# 中的跳脫字元,顯示列建議如何在 C# 中使用和列印它們 -
| 跳脫字元 | 描述 | 模式 | 顯示 |
|---|---|---|---|
| \a | 匹配鈴聲字元,\u0007。 | \a | "Warning!" + '\u0007' 中的 "\u0007" |
| \b | 在字元類中,匹配退格符,\u0008。 | [\b]{3,} | "\b\b\b\b" 中的 "\b\b\b\b" |
| \t | 匹配製表符,\u0009。 | (\w+)\t | "Name\t"、"Addr\t" 中的 "Name\tAddr\t" |
| \r | 匹配回車符,\u000D。(\r 不等效於換行符, .) | \r (\w+) | "\r Hello" 中的 "\r\Hello World." |
| \v | 匹配垂直製表符,\u000B。 | [\v]{2,} | "\v\v\v" 中的 "\v\v\v" |
| \f | 匹配換頁符,\u000C。 | [\f]{2,} | "\f\f\f" 中的 "\f\f\f" |
| 匹配換行符,\u000A。 | \r (\w+) | "\r Hello" 中的 "\r\Hello World." | |
| \e | 匹配轉義符,\u001B。 | \e | "\x001B" 中的 "\x001B" |
nn | 使用八進位制表示法指定字元(nnn 最多包含三個數字)。 | \w\040\w | "a b"、"c d" 中的 "a bc d" |
| \x nn | 使用十六進位制表示法指定字元(nn 恰好包含兩位數字)。恰好包含兩位數字)。 | \w\x20\w | \w\x20\w |
| \c X\c x | 匹配由 X 或 x 指定的 ASCII 控制字元,其中 X 或 x 是控制字元的字母。 | \cC | "\x0003" 中的 "\x0003"(Ctrl-C) |
| \u nnnn | 使用十六進位制表示法匹配 Unicode 字元(恰好四位數字,如 nnnn 所示)。 | \w\u0020\w | "a b"、"c d" 中的 "a bc d" |
| \ | 後跟未被識別為跳脫字元的字元時,匹配該字元。 | \d+[\+-x\*]\d+\d+[\+-x\*\d+ | "2+2" 和 "3*9" 中的 "(2+2) * 3*9" |
以下是一個示例,展示如何在 C# 中使用一些跳脫字元 -
示例
using System;
using System.Collections.Generic;
class Demo {
static void Main() {
Console.WriteLine("Warning!" + '\u0007');
Console.WriteLine("Demo Text \t Demo Text");
Console.WriteLine("This is it!
This is on the next line!");
}
}輸出
Warning! Demo Text Demo Text This is it! This is on the next line!
廣告
資料結構
網路
關係資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP