Public Shared Function Occurs(ByVal tcChar As Char, ByVal cExpression As String) As Integer Dim i As Integer, nOccured As Integer = 0 'Loop through the string For i = 0 To cExpression.Length - 1 Step i + 1 'Check if each expression is equal to the one we want to check against If cExpression.Chars(i) = tcChar Then 'if so increment the counter nOccured = nOccured + 1 End If Next Return nOccured End Function Public Shared Function Occurs(ByVal cString As String, ByVal cExpression As String) As Integer Dim nPos As Integer = 0 Dim nOccured As Integer = 0 Do 'Look for the search string in the expression nPos = cExpression.IndexOf(cString, nPos) If nPos < 0 Then 'This means that we did not find the item Exit Do Else 'Increment the occured counter based on the current mode we are in nOccured = nOccured + 1 nPos = nPos + 1 End If Loop While True 'Return the number of occurences Return nOccured End Function~~Bonnie
> ' Count the occurences of one string within another > ' expC1 Character to look for > ' expC2 String > Public Function Occurs(ByVal tcCharacter As String, ByVal tcString As String) As Integer > Dim lcString As String = "" > Dim lnCount As Integer = 0 > Dim lnLocation As Integer = 0 > lcString = tcString > lnLocation = lcString.IndexOf(tcCharacter) > Do While lnLocation <> -1 > lnCount = lnCount + 1 > lcString = Mid(lcString, lnLocation + 2) > lnLocation = lcString.IndexOf(tcCharacter) > Loop > Return lnCount > End Function >