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- o.
The problem that I am having when I run through the loops is that the spaces and characters are counting for A. so in the case of "Good Food?"
there will be 2- d, 1- f, 1 -g, 4- 0 and 2 - 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 SubPrivate Sub btnsubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsubmit.Click
any help is appreciated!