Solved

counting number of occurances for a specific character in a string

Posted on 2000-03-22
2
2,329 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

823 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