Search Tools Links Login

Count spaces or occurances of words or anything with one simple line of code

Posted: 2003-06-01
By: ArchiveBot
Viewed: 74

Filed Under:

VB6 Code Cache

No attachments for this post


Count spaces or occurances of words or anything with one simple line of code.

Original Author: _+Seanp2k+_

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.

Code

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


Comments on this post

No comments have been added for this post.

You must be logged in to make a comment.