我想将一个字符串数组转换为单个字符串。
string[] test = new string[2];
test[0] = "Hello ";
test[1] = "World!";
我想要一些像“Hello World!”
我想将一个字符串数组转换为单个字符串。
string[] test = new string[2];
test[0] = "Hello ";
test[1] = "World!";
我想要一些像“Hello World!”
当前回答
比使用已经提到的Join()方法稍微快一点的选项是Concat()方法。它不像Join()那样需要空分隔符参数。例子:
string[] test = new string[2];
test[0] = "Hello ";
test[1] = "World!";
string result = String.Concat(test);
因此,它可能更快。
其他回答
是这样的:
string str= test[0]+test[1];
你也可以使用循环:
for(int i=0; i<2; i++)
str += test[i];
Try:
String.Join("", test);
它应该返回一个将两个元素连接在一起的字符串。""表示您希望将字符串连接在一起而不使用任何分隔符。
我用这种方法让我的项目更快:
RichTextBox rcbCatalyst = new RichTextBox()
{
Lines = arrayString
};
string text = rcbCatalyst.Text;
rcbCatalyst.Dispose();
return text;
RichTextBox。文本将自动将您的数组转换为多行字符串!
string[] test = new string[2];
test[0] = "Hello ";
test[1] = "World!";
string.Join("", test);
比使用已经提到的Join()方法稍微快一点的选项是Concat()方法。它不像Join()那样需要空分隔符参数。例子:
string[] test = new string[2];
test[0] = "Hello ";
test[1] = "World!";
string result = String.Concat(test);
因此,它可能更快。