我想将一个字符串数组转换为单个字符串。
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!”
当前回答
string[] test = new string[2];
test[0] = "Hello ";
test[1] = "World!";
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);
Try:
String.Join("", test);
它应该返回一个将两个元素连接在一起的字符串。""表示您希望将字符串连接在一起而不使用任何分隔符。
是这样的:
string str= test[0]+test[1];
你也可以使用循环:
for(int i=0; i<2; i++)
str += test[i];
聚合也可以用于相同的。
string[] test = new string[2];
test[0] = "Hello ";
test[1] = "World!";
string joinedString = test.Aggregate((prev, current) => prev + " " + current);