Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tab Escape Character?

Tags:

c#

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

like image 850
GateKiller Avatar asked Aug 08 '08 09:08

GateKiller


People also ask

What do the \n and \t escape characters represent?

It is used in representing certain whitespace characters: "\t" is a tab, "\n" is a newline, and "\r" is a carriage return.

How do you escape a space character?

You can also add a backslash before whitespace characters such as space, tab, newline and formfeed. However, it is cleaner to use one of the easily readable escape sequences, such as ' \t ' or ' \s ', instead of an actual whitespace character such as a tab or a space.


2 Answers

Easy one! "\t"

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

like image 109
Matt Hamilton Avatar answered Oct 02 '22 20:10

Matt Hamilton


For someone who needs quick reference of C# Escape Sequences that can be used in string literals:

\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)

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.Newline which gets adjusted to current OS settings. With .Net Core it gets really important.

like image 31
andrew.fox Avatar answered Oct 02 '22 18:10

andrew.fox