424,303 Members | 1,339 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,303 IT Pros & Developers. It's quick & easy.

Access 97 and counting the occurrences in a string

P: n/a
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
Nov 13 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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.

--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com
Nov 13 '05 #2

P: n/a
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.


Nov 13 '05 #3

P: n/a

"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

Nov 13 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.