A CountChar Better than looping through a string
It used to be, when I wanted to count the number of times a charector appeared in a string, I would loop through the string letter by letter and keep a count. I have replace my old methodolgies with this one, which also allows you to search for substrings (more than 1-digit long)
Rate A CountChar Better than looping through a string
(7(7 Vote))
Public Function CountChar(vText as String, vChar as String, Optional IgnoreCase as Boolean) as Integer
If IgnoreCase Then
vText = LCase$(vText)
vChar = LCase$(vChar)
End If
Dim L as Integer
L = Len(vText)
vText = Replace$(vText, vChar, "")
CountChar = (L - Len(vText)) / Len(vChar)
End Function
A CountChar Better than looping through a string Comments
No comments yet — be the first to post one!
Post a Comment