使用Visual Studio 2010的C Sharp中的字符串 [英] Strings In C Sharp using Visual Studio 2010
问题描述
大家好.
我正在使用Visual Studio2010.是否可以在使用Visual Studio 2010时用双引号将跨越多行的文本括起来,以将其标记为字符串?例如
Hi all.
I am using Visual Studio 2010. Is there a way, while using Visual Studio 2010, that you can surround text spanning multiple lines with double quotes to mark it as a string? E.g.
My name
is Charles
and i am a programmer
instead of doing it manually by putting double quotes at the beginning and at the end and using ''+'' to join them?
推荐答案
您可以添加双引号或通过转义"其他特殊字符.例如:
You can add double quotes or other special characters by "escaping" them. For example:
string escapedStr = "\"First line\nSecond line\"";
See this site[^] for a list of available escape characters.
As Mattias said you can simply prepend "@" to your string, however you need to be aware that it has some other effects; it causes escape characters to be treated as literals. See this article[^] for more details.
哦,是的.像这样
oh, yes. Like this.
const string mystr = @"
Hello
World";
您可以使用类似以下的内容:
You can use something like this:
string str = "First line.\nSecond line";
\n
char是新行的转义序列.
The \n
char is the escape sequence for a new line.
这篇关于使用Visual Studio 2010的C Sharp中的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!