V suprised I couldn't find a general purpose function that returns the number of times a character appears in a string...
so here's one i made
VB Code:
Public Function OccurrenceInstr(searchStr As String, char As String) As Integer Dim lastSpot As Integer Dim occCount As Integer Dim found As Boolean If searchStr = "" Or char = "" Then Exit Function found = True While found lastSpot = InStr(lastSpot + 1, searchStr, char) If lastSpot > 0 Then occCount = occCount + 1 found = True Else found = False End If Wend OccurrenceInstr = occCount End Function
note: not thoroughly tested




Reply With Quote