occurances in string??

J-F

Registered User.
Local time
Today, 05:58
Joined
Nov 14, 2001
Messages
41
Is there an easy way of finding out how times a certain character occurs within a string.

In other words, String is "asf[asgfsa[sg[dfdf[df[fdg[gf"
How many times does "[" appear.
Answer = 6
 
You have to loop through the string:

Public Function strCount(str As String, strFind As String) As Integer
Dim intLength As Integer
Dim strHold As String
Dim intFind As Integer
intLength = Len(strFind)
strHold = str
intFind = InStr(strHold, strFind)
Do Until intFind = 0
strHold = Mid(strHold, intFind + intLength)
strCount = strCount + 1
intFind = InStr(strHold, strFind)
Loop
End Function
 
Perfect. Thanks.
 

Users who are viewing this thread

Back
Top Bottom