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

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

Edited 5 Years Ago by abelLazm: n/a

This article has been dead for over six months. Start a new discussion instead.