Function to Count Occurrences of Substring within a String
:
Return to List
Public Function CountWithin(ByVal strString As String, ByVal strFind As String) As String
' To count all occurrences of one string in another
Dim intPos As Integer, intLP As Integer, intLen As Integer, strTemp As String
CountWithin = 0
' find each search string and replace with nothing
intLen = Len(strFind)
intPos = InStr(strString, strFind)
While intPos <> 0
CountWithin = CountWithin + 1
strString = Right$(strString, Len(strString) - intPos - intLen + 1)
intPos = InStr(strString, strFind)
Wend
End Function
Note to Webmaster