我想知道如何在没有连续符号的情况下做多行字符串(+)
我试过这个
string a = String.Format(@"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
{0}xxxxxxx", "GGG");
string b = @"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
xxxxxxx";
string c = "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
+ "xxxxxxx";
Console.WriteLine(a);
Console.WriteLine(b);
Console.WriteLine(c);
Run Code Online (Sandbox Code Playgroud)
这可以工作,但前2个渲染很多空白.有没有concat符号写多行而忽略结束空格而不使用像渲染字符串之后的替换?
编辑
using System; using
System.Collections.Generic; using
System.Linq; using System.Text;
namespace ConsoleApplication2 {
public class Test
{
public Test()
{
}
public void MyMethod()
{
string someLongString = "On top of an eager overhead weds a
pressed vat. How does a chance cage
the contract? The glance surprises the
radical wild.";
}
} }
Run Code Online (Sandbox Code Playgroud)
看看它是如何正确的,虽然我的牙箍的形成和坚持(抱歉有点难以在堆栈上显示,但它是坚持到远方).
令人遗憾的是记事本++做得更好,当它包装时它就在变量下面.
只需删除空白区域.它可能不漂亮,但它有效:
string a = @"this is the first line
and this is the second";
Run Code Online (Sandbox Code Playgroud)
请注意,第二行需要一直到左边距:

作为替代方案,您可以使用该\n字符,但之后您不能使用逐字字符串(@ -prefix):
string a = "first line\nsecond line";
Run Code Online (Sandbox Code Playgroud)