I dont want objreader to read spaces or character

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • firebirds98
    New Member
    • Feb 2008
    • 15

    I dont want objreader to read spaces or character

    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.


    Code:
    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!
  • mafaisal
    New Member
    • Sep 2007
    • 142

    #2
    Hello

    Replace All Spaces

    eg
    Code:
    Replace(string, " ", "")
    Now All Spaces are remove then Try

    Faisal

    Originally posted by firebirds98
    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.


    Code:
    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!

    Comment

    • firebirds98
      New Member
      • Feb 2008
      • 15

      #3
      thanks for the help with the remove space problem

      the problem now has something to do with my select case function. If int = selectletterCas e(sLine.Substri ng(i - 1, 1))

      is sent either an "a" , " space " or " any type of character " it returns 0 and will add 1 to the total count for "a"

      Comment

      • firebirds98
        New Member
        • Feb 2008
        • 15

        #4
        figured it out.

        Need a Case Else that returns a null.

        Comment

        Working...