ตาราง Escape Characters ใน C# และวิธีแสดงผล
| Escape Char | คำอธิบาย | Pattern | Display |
|---|---|---|---|
| \a | Bell (\u0007) | \a | "\u0007" ใน "Warning!" + '\u0007' |
| \b | Backspace (\u0008) | [\b]{3,} | "\b\b\b\b" ใน "\b\b\b\b" |
| \t | Tab (\u0009) | (\w+)\t | "Name\t", "Addr\t" ใน "Name\tAddr\t" |
| \r | Carriage Return (\u000D) | \r\n(\w+) | "\r\nHello" ใน "\r\Hello\nWorld." |
| \v | Vertical Tab (\u000B) | [\v]{2,} | "\v\v\v" ใน "\v\v\v" |
| \f | Form Feed (\u000C) | [\f]{2,} | "\f\f\f" ใน "\f\f\f" |
| \n | New Line (\u000A) | \r\n(\w+) | "\r\nHello" ใน "\r\Hello\nWorld." |
| \e | Escape (\u001B) | \e | "\x001B" ใน "\x001B" |
| \nnn | Octal (3 digits) | \w\040\w | "a b", "c d" ใน "a bc d" |
| \x nn | Hex (2 digits) | \w\x20\w | \w\x20\w |
| \c X | ASCII Control (Ctrl-X) | \cC | "\x0003" ใน "\x0003" (Ctrl-C) |
| \u nnnn | Unicode (4 hex digits) | \w\u0020\w | "a b", "c d" ใน "a bc d" |
| \ | Escape unknown char | \d+[\+-x\*]... | "2+2", "3*9" ใน "(2+2) * 3*9" |
ตัวอย่างการใช้งาน
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!\nThis is on the next line!");
}
}
Output
Warning! Demo Text Demo Text This is it! This is on the next line!