Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

counting number of occurances for a specific character in a string

Posted on 2000-03-22
2
Medium Priority
?
2,334 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

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.
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

670 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