Return to Snippet

Revision: 28957
at July 17, 2010 04:21 by Shurik76


Initial Code
<%
'Counts number of occurrences of a certain char(s) in a string, returns number
Function CharCount(SourceString, CharsToFind)

LengthOfSourceString = Len(SourceString)
LengthOfCharsToFind = Len(CharsToFind)

If LengthOfCharsToFind >= LengthOfSourceString Then
    If LCase(CharsToFind) = LCase(SourceString) Then
        CharCount = 1
    Else
        CharCount = 0
    End If
    Exit Function
Else
    LoopLength = (LengthOfSourceString - LengthOfCharsToFind) + 1
    OccurrenseCounter = 0
    For i=1 to LoopLength
        CurrentSample = Mid(SourceString,i,LengthOfCharsToFind)
        If LCase(CurrentSample) = LCase(CharsToFind) Then
            OccurrenseCounter = OccurrenseCounter + 1
        Else
        End If
    Next
    CharCount = OccurrenseCounter
End If

End Function
%>

Initial URL

                                

Initial Description
Count the Number of Occurrences of a Character Sequence in a String

Initial Title
Character Count

Initial Tags

                                

Initial Language
ASP