0

Hey....I face some problem in counting the repeated times of items...hope somebody can helps me..

For example:
I have a list of data that store in string array

1
2
1
2
3
1
2
3
2
2
3
4
2
4
5
2
3
.........

(maybe have different numbers)
now i wan to count each item repeated times

item        values
1               3
2               5
3               4
4               2
5               1

after that, i need to sort them based on the values from highest to lowest.

item        values
2                5
3                4
1                3
4                2
5                1

this is the output that i expected.Hope someone will help me..thanks ya.
here is my coding:

                    String[] sArray = new String[showFile1.Lines.Length];
                    int p = 0;
                    foreach (String k in listItem.Keys)
                    {
                        sArray[p] = k;
                        show += sArray[p]+"\n";                          
                        p++;
                    } //MessageBox.Show(show.ToString());

                    KeyItems1 = show.Split(' ');
                    String display = "";
                    ArrayList list = new ArrayList();
                    foreach (string h in KeyItems1)
                    {
                        display += h + "\n"; 

                    }
                    list.Add(display);                     
                    String display2 = "";
                    foreach (string i in list)
                    {
                        display2 += i ;
                    } 
                    //MessageBox.Show(display2.ToString());

                    String[] sArray2 = list.ToArray(typeof(String)) as String[];
                    String display3 = "";
                    foreach (String value in sArray2)
                    {
                        display3 += value;
                    }

Edited by mike_2000_17: Fixed formatting

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by Mitja Bonca
0

Mate, if this is not you final version of the project, I wont even help you out.
That it wont be like last time, when I did the code for you (school homework I guess), and then you came out later to ungrade it.
No, cant do.

So, what is it gonna be?
Is this it, or not?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.