How do you write the tab (\ t) inside the line "@ ..." in C #?

Possible duplicate:
C # @ "" how to insert a tab?

I'm trying to just use a tab on my keyboard, but the compiler interprets the tabs as spaces. Using \t will not work either, it will interpret it as \t literally. Is it impossible or am I missing something?

 string str = @"\thi"; MessageBox.Show(str); // Shows "\thi" 
+8
c # escaping
source share
5 answers

in VS2010 - if you copy to the clipboard from a richtext application, and this content has a tab, I believe that it will be inserted into the VS2010 editor as such.

(I consider this on the side of the buggy and will not be surprised if the behavior changes in the future)

+3
source share

Separate the line and paste \t to where you want?

 var str = @"This is a" + "\t" + @"tab"; 
+11
source share

The whole point of a literal string literal is that escaping is disabled so that backslashes can be read as they are written. If you want to escape, use a regular string literal (without the at character).

You could, of course, put a literal tab character (by pressing the tab key) inside the line.

+6
source share

Another option is to specify the tab as a parameter in the .Format line:

 string.Format(@"XX{0}XX", "\t"); // yields "XX XX" 
+5
source share

You are using a string literal .

Instead, simply do the following:

 string str = "\thi"; MessageBox.Show(str); 
+2
source share

All Articles