连接到逐字字符串文字,大量文本换行
Concatenating To A Verbatim String Literal With Large Volume Of Text Breaking Into New Line
如何将逐字字符串文字中的变量与大量换行的文本连接起来?我正在使用 stringbuilder 附加所有字符串变量,但
我打算做什么 -
StringBuilder sbuilder = new StringBuilder();
variable y = something
variable x = @"text"+ y + "
other text other text";
variable z = @"blablabla";
variable z2 = @"some other text"
sbuilder.Append(x);
sbuilder.Append(z);
sbuilder.Append(z2);
string html = sbuilder.ToString();
我试过的 -
var variable = modelview.something;
string form = @"a whole lotta text "+variable+ "even more text";
我收到语法错误
Represents text as a series of Unicode characters.To browse the .NET framework source code for this type, see the Reference Source.
Newline in constant
也许您正在寻找这样的东西。
string myVar = "hello";
string form = $@"My String {myVar}";
要么通过插值
string from = $@"a whole lotta text {variable} even more text";
或通过连接
string from = @"a whole lotta text" + variable + @"even more text";
您可以随时使用 string.Concat()
string a = @"a";
string b = @"b";
string.Concat(a, b); // returns "ab"
有几种方法可以做到这一点。
一种是经典方式
var variable = modelview.something;
string form = @"a whole lotta text " + variable + @" even more text";
另一种方法是使用$
字符串插值
var variable = modelview.something;
string form = $@"a whole lotta text {variable} even more text";
这段代码等同于
var variable = modelview.something;
string form = string.Format(@"a whole lotta text {0} even more text", variable);
如何将逐字字符串文字中的变量与大量换行的文本连接起来?我正在使用 stringbuilder 附加所有字符串变量,但
我打算做什么 -
StringBuilder sbuilder = new StringBuilder();
variable y = something
variable x = @"text"+ y + "
other text other text";
variable z = @"blablabla";
variable z2 = @"some other text"
sbuilder.Append(x);
sbuilder.Append(z);
sbuilder.Append(z2);
string html = sbuilder.ToString();
我试过的 -
var variable = modelview.something;
string form = @"a whole lotta text "+variable+ "even more text";
我收到语法错误
Represents text as a series of Unicode characters.To browse the .NET framework source code for this type, see the Reference Source.
Newline in constant
也许您正在寻找这样的东西。
string myVar = "hello";
string form = $@"My String {myVar}";
要么通过插值
string from = $@"a whole lotta text {variable} even more text";
或通过连接
string from = @"a whole lotta text" + variable + @"even more text";
您可以随时使用 string.Concat()
string a = @"a";
string b = @"b";
string.Concat(a, b); // returns "ab"
有几种方法可以做到这一点。
一种是经典方式
var variable = modelview.something;
string form = @"a whole lotta text " + variable + @" even more text";
另一种方法是使用$
字符串插值
var variable = modelview.something;
string form = $@"a whole lotta text {variable} even more text";
这段代码等同于
var variable = modelview.something;
string form = string.Format(@"a whole lotta text {0} even more text", variable);