Imports System
Imports System.Collections.Generic
Public Class Program
Public Shared Sub Main()
Dim str As String = "Visual Basic (VB), originally called Visual Basic .NET (VB.NET), " +
"is a multi-paradigm, object-oriented programming language, implemented on " +
".NET, Mono, and the .NET Framework. Microsoft launched VB.NET in 2002 as the" +
"successor to its original Visual Basic language"
Dim wordCount As Dictionary(Of String, Integer) = CountWords(str)
For Each word In wordCount
Console.WriteLine($"{word.Key}: {word.Value}")
Next
End Sub
Public Shared Function CountWords(ByVal input As String) As Dictionary(Of String, Integer)
Dim wordCount = New Dictionary(Of String, Integer)(StringComparer.OrdinalIgnoreCase)
Dim words = input.Split({" "c, "."c, ","c, "!"c, "?"c, ";"c, ":"c, "-"c, Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries)
For Each word In words
If wordCount.ContainsKey(word) Then
wordCount(word) += 1
Else
wordCount(word) = 1
End If
Next
Return wordCount
End Function
End Class
' run:
'
' Visual: 3
' Basic: 3
' (VB): 1
' originally: 1
' called: 1
' NET: 4
' (VB: 1
' NET): 1
' is: 1
' a: 1
' multi: 1
' paradigm: 1
' object: 1
' oriented: 1
' programming: 1
' language: 2
' implemented: 1
' on: 1
' Mono: 1
' and: 1
' the: 1
' Framework: 1
' Microsoft: 1
' launched: 1
' VB: 1
' in: 1
' 2002: 1
' as: 1
' thesuccessor: 1
' to: 1
' its: 1
' original: 1
'