如何在“@...”内写入制表符 (\t) C# 字符串?
可能的重复:
C# @“”如何插入制表符?
C# @“”如何 尝试只使用键盘上的制表符,但编译器将制表符解释为空格。使用 \t
也不起作用,它会按字面意思将其解释为 \t
。这是不可能的还是我错过了什么?
string str = @"\thi";
MessageBox.Show(str); // Shows "\thi"
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"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
分割你的字符串并在你想要的地方插入一个
\t
?Split your string and insert a
\t
where you want it?逐字字符串文字 是关闭转义,以便可以在写入反斜杠时读取它们。如果您想转义,请使用常规字符串文字(不带 at 符号)。
当然,您可以在字符串中放置一个文本制表符(通过按 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.
另一种选择是将制表符指定为 string.Format 中的参数:
Another option is to specify the tab as a parameter in string.Format:
在 VS2010 中 - 如果您从富文本应用程序复制到剪贴板,并且该内容中有一个选项卡,我相信它将粘贴到 VS2010 编辑器中。
(我认为这有利于越野车,如果未来行为发生变化,我不会感到惊讶)
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: