Search Tools Links Login

Count String Occurances


Count the number of string occurrences inside another string.

Public Function Count(Source As String, Countee As String) As Long
   Dim I As Long, iCount As Integer
   iCount = 0
   I = 1
   Do
      If (I > Len(Source)) Then Exit Do
      I = InStr(I, Source, Countee, vbTextCompare)
      If I Then
         iCount = iCount + 1
         I = I + 1
         DoEvents
      End If
   Loop While I
   sCount = iCount
   Exit Function
   CountError:
   sCount = 0
   Exit Function
End Function

About this post

Posted: 2020-08-30
By: vb6boy
Viewed: 185 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.