Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

counting number of occurances for a specific character in a string

Posted on 2000-03-22
2
Medium Priority
?
2,336 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 200 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

782 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