1
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?

2
  • Do you want to have an list of arrays, or do you want to merge the results into a single sequence? Commented Sep 4, 2012 at 16:47
  • 1
    I'm assuming that there's more code in between those foreach statements otherwise they don't make much sense why you'd be doing the foreach within another foreach that doesn't seem to be related. Commented Sep 4, 2012 at 16:48

3 Answers 3

2

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(','));
            }
        }
Sign up to request clarification or add additional context in comments.

4 Comments

If that's what he actually wants to do, yes.
Conditional appears to be redundant. Just take the AddRange branch. Split will return an array containing the whole string value if the split character is not found.
Thanks a lot, this worked just fine, i do not need the if statement
I removed the if statement from my answer yesterday - don't forget to mark as answer. Glad I was able to help.
0

declare as

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

and add as

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

Comments

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

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

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

    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.