Sector3 Sector3 - 4 years ago 160
C# Question

Array Indexer to string builder

Code :

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]);
}


The information inside string[] :


X = 1,2,3

A = 4,5,6

B = 7,8,9

C = Adam,Mark,Tom

D = 16,21,88


The Result will Return :


147Adam16

258Mark21

369Tom88


What i trying to achieve :


string newstring = 147Adam16258Mark21369Tom88


It's there anyway to achieve it with a simple solution?

Answer Source
    `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());`

Do mark as answer if it helps.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download