Solved

# counting number of occurances for a specific character in a string

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

LVL 9

Accepted Solution

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

ID: 2647112
Thanks Brian.

-jptu
0

## Featured Post

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
###### Suggested Courses
Course of the Month9 days, 2 hours left to enroll

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

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