Dim str As String = "This is a test. This is only a test."
Dim iChrs, iWords As Integer
'get the number of characters:
iChrs = str.Length
'remove the double spacing between sentences:
str = str.Replace(" ", " ")
'get the number of words:
iWords = str.Split(" ").Length
str = str.Replace(" ", " ")
str = str.Replace(" ", " ") ' NOTE: Two Spaces for the first argument
Function CountWords(ByVal Text As String) As Integer
Dim r As Regex
Dim m As Match
Dim counter As Integer
r = New Regex("\b\w+\b")
m = r.Match(TextBox1.Text)
While m.Success
counter += 1
m = m.NextMatch()
End While
Return counter
End Function
Schenz said:Are there two spaces in the first part of the line?
This messageboard seems to be taking the double space we're attempting to put there and making it just one space.
Dim str As String
Dim ichar, iWords As Integer
'get the number of characters:
str = T1.Text
ichar = str.Length
L1.Text = ichar
'remove the double spacing between sentences:
str = str.Replace(" ", " ")
'get the number of words:
Dim tempString As String = Trim(str.Replace(" ", " "))
iWords = tempString.Split(" ").Length
T2.Text = iWords