Counting Characters less whitespace, with Regular Expression
Posted on 2006-06-08
I'm trying to count the words and characters in a text box. I picked up the CountWords function from a post by TheLearnedOne and it works great. I was trying to build off of it and make a function that would count all characters with the exception of any whiteSpace. The function I wrote, CountCharacters is not working. Any help in counting the characters without counting spaces would really be appreciated.
Public Shared Function CountWords(ByVal inputText As String) As Integer
Dim patternWords As String = "[\w]+"
Dim regCountWords As New System.Text.RegularExpressions.Regex(patternWords)
End Function 'CountWords'
Public Shared Function CountCharacters(ByVal inputText As String) As Integer
Dim patternCharacters As String = "[^:Wh]"
Dim regCountCharacters As New System.Text.RegularExpressions.Regex(patternCharacters)
End Function 'CountCharacters'