JustCode : Count number of characters

Code to count the number of times a specific character apears in a string.

Function CountChars(sString,sLookFor)
    Dim iCount,iChar

    For iChar = 0 to Len(sString)-1
        If ( mid(sString,iChar,1) = sLookFor ) Then
            iCount = iCount + 1
        End If
    Next
    CountChars = iCount
End Function

Leave a Comment