/ Published in: ASP
Count the Number of Occurrences of a Character Sequence in a String
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<% '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 %>