开发者

How do you write a tab (\t) inside a "@..." C# string? [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

C# @“” how do i i开发者_如何学Cnsert 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"


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"


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

(i consider this on the side of buggy and wouldn't be surprised if the behavior changes in the future)


You are using a string literal.

Instead, just do this:

string str = "\thi";
MessageBox.Show(str);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜