Solved

counting number of occurances for a specific character in a string

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

911 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

16 Experts available now in Live!

Get 1:1 Help Now