Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Private Function CollectWords() As Dictionary(Of String, Integer)
- ' create a new dictionary
- Dim table As New Dictionary(Of String, Integer)
- Console.WriteLine("Enter a string: ") ' prompt for user input
- Dim input As String = Console.ReadLine() ' get input
- ' split input text into tokens (words)
- Dim words As String() = input.Split()
- ' processing input words
- For Each word In words
- Dim wordKey As String = word.ToLower() ' get word in lowercase
- Dim letters As Char() = word.ToCharArray()
- ' if the dictionary contains the word
- If table.ContainsKey(wordKey) Then
- table(wordKey) = table(wordKey) + 1
- Else
- ' add new word with a count of 1 to dictionary
- table.Add(wordKey, 1)
- End If
- For Each letter In letters
- If table.ContainsKey(letter) Then
- table(letter) = table(letter) + 1
- Else
- table.Add(letter, 1)
- End If
- Next
- Next
- Return table
- End Function ' CollectWords
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement