Possible Duplicate:
C# @“” how do i insert a tab?
I'm trying to just use the tab on my keyboard but the compiler interprets the tabs as spaces. Using \t
won't work either, it will interpret it as \t
literally. Is it not possible or am I missing something?
string str = @"\thi";
MessageBox.Show(str); // Shows "\thi"
\t (Horizontal tab) – We use it to shift the cursor to a couple of spaces to the right in the same line.
Tab characters. The most known and common tab is a horizontal tabulation (HT) or character tabulation, which in ASCII has the decimal character code of 9, and may be referred to as Ctrl + I or ^I. In C and many other programming languages the escape sequence \t can be used to put this character into a string literal.
'\t' is a horizontal tab . It is used for giving tab space horizontally in your output.
Split your string and insert a \t
where you want it?
var str = @"This is a" + "\t" + @"tab";
The whole point of a verbatim string literal is that escaping is turned off such that backslashes can be read as they are written. If you want escaping, then use a regular string literal (without the at symbol).
You could, of course, put a literal tab character (by pressing the tab key) within the string.
Another option is to specify the tab as a parameter in string.Format:
string.Format(@"XX{0}XX", "\t"); // yields "XX XX"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With