please help string count

lekner

Member
Joined
Sep 18, 2007
Messages
5
Programming Experience
Beginner
thanks in advance
having a problem and cant solve it :-(

i am having a text file and i need to do complex (for me) count on it
the text look like that (the stars are text and numbers)

***************************************************************************************************************************************************************************
then i have x y z there are spaces between them

x y z
5 4535
6 4545
2 335553

i need to write code that will count how many same numbers i have under x
and the sum of there z like
number 5 i have 3 times and the sum of all the fives is 233524
the numbers are from 1 to 13 but if i can make one to work i can make all of them to work
please help if you can
the main problem is thet there are a lot of numbers in the text
but i need only the first row i know when the first row start
i know where the z starts for each x starts +- 2 spaces in front and back

i know its long but please help me
the only thing i was able to do is to count all the fives but i counted all of them in the text not the first row

please please help if you can
 
sorry the long numbers 4535 etc are under z the y is something else and there are also numbers there and there is a lot of text under all the x row is finished
 
VB.NET:
        Dim values() As Integer = New Integer() {3, 5, 7, 3, 7, 3, 3, 7, 7, 5, 7, 7, 7, 5, 7}
        Dim counter As New Dictionary(Of Integer, Integer)()

        If values.Length > 0 Then
            For Each i As Integer In values
                If Not counter.ContainsKey(i) Then
                    counter(i) = 1
                Else
                    counter(i) += 1
                End If
            Next

            For j As Integer = 0 To 13
                If counter.ContainsKey(j) Then
                    MessageBox.Show(j.ToString() + " appears " + counter(j).ToString() + " times in the list")
                Else
                    MessageBox.Show(j.ToString() + " does not appear in the list")
                End If
            Next

        Else
            MessageBox.Show("the list conatained no element")
        End If

I have made this that will count the occurences of each number from 0 to 13 in the list, but I don't get how you can say

number 5 i have 3 times and the sum of all the fives is 233524

Shoudn't the sum of 3 fives be 3x5 = 15? At least, it cannot be a number that cannot be divided by 5! Could you explain that bit further?
 
Back
Top