Solved

counting number of occurances for a specific character in a string

Posted on 2000-03-22
2
2,326 Views
Last Modified: 2012-05-04
Is there a function which counts the number of times a specific character appears within a string?  For example, I would like the function to count how many times the comma appears in the following string: "x,a,b,c".
0
Comment
Question by:jptu
2 Comments
 
LVL 9

Accepted Solution

by:
BrianWren earned 50 total points
ID: 2647076
Nope.


Public Function CountToken(tk As String, st as String) As Integer

     Dim i as integer
     Dim c as Integer

     For i = 1 to Len(st)
          If Mid$(st, i, 1) = tk Then c = c + 1
     Next i
 
     CountToken = c

End Function



Add this to a module, and you'll have your very own though.  :o)

  a = CountToken(",", "x,a,b,c")

will set a = to 3.

Brian
0
 

Author Comment

by:jptu
ID: 2647112
Thanks Brian.

-jptu
0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now