Advertisement
Guest User

Untitled

a guest
Apr 25th, 2015
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. Private Function CollectWords() As Dictionary(Of String, Integer)
  2. ' create a new dictionary
  3. Dim table As New Dictionary(Of String, Integer)
  4.  
  5. Console.WriteLine("Enter a string: ") ' prompt for user input
  6. Dim input As String = Console.ReadLine() ' get input
  7.  
  8. ' split input text into tokens (words)
  9. Dim words As String() = input.Split()
  10.  
  11.  
  12.  
  13. ' processing input words
  14. For Each word In words
  15. Dim wordKey As String = word.ToLower() ' get word in lowercase
  16. Dim letters As Char() = word.ToCharArray()
  17.  
  18. ' if the dictionary contains the word
  19. If table.ContainsKey(wordKey) Then
  20. table(wordKey) = table(wordKey) + 1
  21. Else
  22. ' add new word with a count of 1 to dictionary
  23. table.Add(wordKey, 1)
  24. End If
  25.  
  26. For Each letter In letters
  27. If table.ContainsKey(letter) Then
  28. table(letter) = table(letter) + 1
  29. Else
  30. table.Add(letter, 1)
  31. End If
  32. Next
  33.  
  34. Next
  35.  
  36. Return table
  37.  
  38. End Function ' CollectWords
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement