Hi...now i doing split. i got face some problems.
Let say,

I got store my data in string type
1 2
1 2 3
1 2 3 4

now i want it to split line by line.But after i split them, i got the result is like this
1
2
1
2
3
1
2
3
4

this is what i don't want.
the expected output that i want are:
Output1:
1
2
output2
1
2
3
output3
1
2
3
4
and so on..
Hope somebody help me to solve this problem. thanks ya.
here is my coding.

List<KeyValuePair<String, int>> P = new List<KeyValuePair<String, int>>(itemS.ToList());                     
                        KeyitemS.Clear();

                        String[] SplitA;
                        String[] SplitB;
                        List<String> l = new List<String>();
                        foreach (KeyValuePair<String, int> pair in P)
                        {
                            KeyitemS.AppendText(pair.Key + ":" + pair.Value + "\r\n");
                            l.Add(pair.Key);
                        }

                        List <String> U =new List<String>();
                        foreach (string inter in l)
                        {
                           // MessageBox.Show(inter);
                            SplitA = inter.Split(' ');
                            SplitB = new String[SplitA.Length];
                            for (int i = 0; i < SplitA.Length; i++)
                            {
                                SplitB[i] = SplitA[i];
                               // MessageBox.Show(SplitB[i]);
                                U.Add(SplitB[i]);  
                            }                      
                        }
                        foreach (string gg in U)
                        {
                            MessageBox.Show(gg);
                        }

Recommended Answers

All 3 Replies

First split you items in a string array on the basis of '\n \r' and then split them on the basis of space. Sample code:

List<String> l = new List<String>();
                        foreach (KeyValuePair<String, int> pair in P)
                        {
                            KeyitemS.AppendText(pair.Key + ":" + pair.Value + "\r\n");
                            l.Add(pair.Key);
                        }
SplitA=new string[l.length];
int k=0;
                        List <String> U =new List<String>();
                        foreach (string inter in l)
                        {
                           // MessageBox.Show(inter);
                            SplitA[k] = inter;
                           k++

                            }

for(int j=0;j<SplitA.Length; j++)
{
U.Add("OutPut"+j+1);
SplitB=SplitA[j].Split(' ');     
for (int i = 0; i < SplitB.Length; i++)
    {
          U.Add(SplitB[i]);  
        }                      
  }
                       
                        foreach (string gg in U)
                        {
                            MessageBox.Show(gg);
                        }
SplitA=new string[l.length];

but, this code got error....

check this code instead

SplitA=new string[l.Count];
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.