0

I am trying to write a program that reads in a text file and prints out how many # of each letter shows up for example if my text files is "Good food"

there will be 2- d, 1- f, 1 -g, 4- 0.

The problem that I am having when I run through the loops is that the spaces are counting for A. so in the cause of "Good Food"
there will be 2- d, 1- f, 1 -g, 4- 0 and 1 - A.

Here is my sub with the loop.

Private Sub btnsubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsubmit.Click
       
 Dim i, j, k, l, x As Integer
    Dim lettercount(26) As Integer
    Dim digramCount(26, 26) As Integer
    Dim letterArray(26) As Label
        Dim objReader As New StreamReader("test.txt")
        Dim sLine As String = ""
        Dim arrText As New ArrayList()

        Do
            sLine = objReader.ReadLine()
            If Not sLine Is Nothing Then
                arrText.Add(sLine)
            End If
        Loop Until sLine Is Nothing
        objReader.Close()

        For Each sLine In arrText
            Console.WriteLine(sLine.ToLower)
        Next
        Console.ReadLine()

            For j = 0 To lettercount.Length - 1
                lettercount(j) = 0
            Next

            For k = 0 To 25
                For l = 0 To 25
                    digramCount(k, l) = 0
                Next
            Next

            For i = 1 To sLine.Length
                Dim int As Integer
                int = selectletterCase(sLine.Substring(i - 1, 1))
                lettercount(int) += 1
            Next

            For x = 0 To 25
                letterArray(x).Text = lettercount(x).ToString
                MsgBox(letterArray(x).ToString)
            Next
        End If
    End Sub

any help is appreciated!

1
Contributor
1
Reply
2
Views
9 Years
Discussion Span
Last Post by firebirds98
0

I realized that ith as something to do with my select case function. If there is either a space or a character such as (. , / ? -) it will send it to the case and return a 0 by deafult because there is not a case for the characters. my problem is that "a" returns the value 0 and when either a space or character is sent to the select case function its + 1 to the total # of A's in the string

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.