floormind
floormind

Reputation: 2028

C# - splitting string of each value in an array

foreach (set.row officeJoin in officeJoinMeta)
{
    foreach (set.somethingRow confRow in myData.something.Rows)
    {
        string dep = confRow["columnName"].ToString();
        depts.Add(dep);
    }
}

I've got this for-loop going through a column, adding each value in a column to dep, and later storing all these in a List < String > depts which i defined at the top of this method.

Some of the values in the dep are single strings like "R" but some are need to be separated after the comma "R,GL,BD".

I understand using .Split(","), but how do i split strings--how do i get each value in the array, split them with the comma, then store them in another array?

Upvotes: 1

Views: 2525

Answers (3)

Rahul Ranjan
Rahul Ranjan

Reputation: 1058

List<string> depts=new List<dept>();

    var values=dept].Split(',');

    for(int index=0;index<values.length;index++)
    {
    depts.Add(values[index].ToString());    

    }

Upvotes: 0

McAden
McAden

Reputation: 13972

Written based on what you've explained:

        foreach (set.row officeJoin in officeJoinMeta)
        {
            foreach (set.somethingRow confRow in myData.something.Rows)
            {
                string dep = confRow["columnName"].ToString();
                depts.AddRange(dep.Split(','));
            }
        }

Upvotes: 2

L.B
L.B

Reputation: 116118

declare as

List<string[]> depts =  new List<string[]>()

and add as

depts.Add(dep.Split(','));

Upvotes: 0

Related Questions