CodeItBetter Programming Another VB Programming Blog

How to count the number of occurrences of a substring inside another string

Posted on August 16, 2011
1
2
3
4
5
6
7
'String Manipulation - How to count the number of occurrences of a substring inside another string
Function InstrCount(Source As String, Search As String) As Long
    ' You get the number of substrings by subtracting the length of the 
    ' original string from the length of the string that you obtain by 
    ' replacing the substring with another string that is one char longer.
    InstrCount = Len(Replace(Source, Search, Search & "*")) - Len(Source)
End Function
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


 

No trackbacks yet.