Results 1 to 17 of 17

Thread: [RESOLVED] Another Dictionary Question

Threaded View

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2014
    Posts
    31

    Resolved [RESOLVED] Another Dictionary Question

    Hey all,

    I am trying to use a dictionary to store words and keep a count of how many times the word gets used in a file.

    I open the .txt file and read everything into a string and then split the string. I am then looping thru the words and would like to check each word with the dictionary.
    If the word is not in the dictionary I would like to add the word and give it a value of 1 being that the word has been seen 1 time.
    If the word is found in the dictionary I would like to update the count to 2 being it has been seen twice, 3 then 4, for as many times as the word is seen.

    When the loop is thru the dictionary should have each word it found and how many times it is found.

    For example I read the txt (The actual files will be much longer. This example is just for brevity)

    The one here is not the same as the one there.

    The dictionary should be

    The,3
    one,2
    here,1
    is,1
    not,1
    same,1
    as,1
    there.,1

    Here is what I have so far.

    Code:
            Dim WordTotal As New Dictionary(Of String, Integer)
            Dim CountWords As String = IO.File.ReadAllText(OriginalTextFile)
    
            Dim CountWord() As String = CountWords.Split(" "c)
            Dim SingleWord As String
            For Each SingleWord In CountWord
                If WordTotal.ContainsKey(SingleWord) Then
    
                End If
            Next
    Also if there is a better way to do what I am trying to do please feel free to share the options.
    My skill set with VB is limited and I learn a lot from people here.
    Last edited by bwquestion; Sep 1st, 2014 at 09:04 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width