Counting the number of instances of a string within another string
Counting the number of instances of a string within another string
Rate Counting the number of instances of a string within another string
(2(2 Vote))
Dim asItems() As String, lThisItem As Long
On Error GoTo ErrFailed
If bIgnoreCase Then
asItems = Split(UCase$(sText), UCase$(sSearchFor))
CountString = UBound(asItems)
Else
asItems = Split(sText, sSearchFor)
CountString = UBound(asItems)
End If
If Len(sIgnoreText) Then
'Deduct any items which contain the specified "sIgnoreText"
For lThisItem = 0 To UBound(asItems) - 1
If asItems(lThisItem) = sIgnoreText Then
'Deduct this item
CountString = CountString - 1
End If
Next
End If
Exit Function
ErrFailed:
'Error occurred
Debug.Print "Error in CountString " & Err.Description
Debug.Assert False
CountString = 0
End Function
Counting the number of instances of a string within another string Comments
No comments yet — be the first to post one!
Post a Comment