by _+Seanp2k+_ (2 Submissions)
Category: Coding Standards
Compatability: Visual Basic 5.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (4 Votes)
Count spaces or occurances of words or anything with one simple line of code.
Inputs
text1.text would be the string you want to count the occurances in. this particular code would count how amny times "hi" appears in text1.text
a common use of this to count both lower and uppercase would to first use the line
text1.text = Lcase(text1.text) to make text1 all lower case. you coudl aslo use this
searchtextbox.text = lcase(searchtextbox.text)
occuranceslabel.caption= ubound(split(document.text, searchtextbox.text))
that would put in occuranceslabel the number of times that the text in searchtextbox appears in the document textbox.
Ubound(Split(text1.text,"hi"))
this can easily be transformed into a function
Public Function fCount(ByVal sString As String, ByVal sDelim As String) As Long
fCount = 0
On Error Resume Next
fCount = UBound(Split(sString, sDelim))
End Function
No comments have been posted about Count spaces or occurances of words or anything with one simple line of code. Why not be the first to post a comment about Count spaces or occurances of words or anything with one simple line of code.