"sparks" <js******@swbell.net> wrote in message
news:8l********************************@4ax.com...
yes that is what I did...someone was saying that access2003 had this
built in with the new vb.net code.
just checking
jerry
On Tue, 13 Sep 2005 12:58:25 GMT, "Rick Brandt"
<ri*********@hotmail.com> wrote:
sparks wrote: Besides doing a loop is there a command that will give the number of
occurreneces of a chr in a string?
The only way I can think of is to do a while loop and count variable.
thanks for info
Jerry
We all have utility functions for stuff that comes up like this over and
over. Just put your loop code into a function and then use that wherever
you need to do this.
In versions later than A97, you have a Replace function which makes no
looping necessary. If you wanted to use this code in A97, you would just
have to write the Replace function yourself.
Public Function CountSubstrings(MainString As String, _
SubString As String, _
Optional CaseSensitive _
As Boolean = False) As Long
' Function returns zero if SubString=""
If Len(SubString) < 1 Then Exit Function
If CaseSensitive Then
CountSubstrings = (Len(MainString) - _
Len(Replace(MainString, SubString, _
"", , , vbBinaryCompare))) \ Len(SubString)
Else
CountSubstrings = (Len(MainString) - _
Len(Replace(MainString, SubString, _
"", , , vbTextCompare))) \ Len(SubString)
End If
End Function