代码:
string[] X = Regex.Split(X, ",");
string[] A = Regex.Split(A, ",");
string[] B = Regex.Split(B, ",");
string[] C= Regex.Split(C, ",");
string[] D = Regex.Split(D, ",");
for (int i = 0; i < splitfirsts.Length; i++)
{
Console.WriteLine("{0}{1}{2}{3}{4}",
X[i], A[i], B[i], C[i], D[i]);
}
string []中的信息:
X = 1,2,3
A = 4,5,6
B = 7,8,9
C =亚当,马克,汤姆
D = 16,21,88
结果将返回:
147Adam16
258Mark21
369Tom88
我想要实现的目标:
string newstring = 147Adam16258Mark21369Tom88
无论如何,通过一个简单的解决方案实现它?
答案 0 :(得分:1)
您无需使用字符串构建器即可实现此目的。如果您只想输出147Adam16258Mark21369Tom88
,则可以使用Console.Write
。试试这个:
for (int i = 0; i < splitfirsts.Length; i++)
{
Console.Write("{0}{1}{2}{3}{4}",
X[i], A[i], B[i], C[i], D[i]);
}
但是,如果您想存储它,可以使用StringBuilder
:
StringBuilder sb = new StringBuilder();
for (int i = 0; i < splitfirsts.Length; i++)
{
sb.AppendFormat("{0}{1}{2}{3}{4}",
X[i], A[i], B[i], C[i], D[i]);
}
Console.Write(sb);
希望它有所帮助!
答案 1 :(得分:0)
string[] X = Regex.Split(X, ",");
string[] A = Regex.Split(A, ",");
string[] B = Regex.Split(B, ",");
string[] C= Regex.Split(C, ",");
string[] D = Regex.Split(D, ",");
StringBuilder sb = new StringBuilder();
for (int i = 0; i < splitfirsts.Length; i++)
{
sb.AppendFormat("{0}{1}{2}{3}{4}",
X[i], A[i], B[i], C[i], D[i]);
}
Console.WriteLine(sb.ToString());