Free Programming Tutorials & Source Code

 
  • Increase font size
  • Default font size
  • Decrease font size
Home Visual Basic.NET Count Words in a Text String in VB.NET

Count Words in a Text String in VB.NET

E-mail
(1 vote, average: 5.00 out of 5)
A simple function that count number of words in a given text string, assuming that it’s delimited by spaces:



 
    Function countwords(ByVal str As String)
        Dim result As Integer
        result = UBound(Split(Trim(Replace(str, Space(2), Space(1))))) + 1
        Return result
    End Function


Happy Coding!