Count Dash Space and Apostrophe in string

Experts,
I am in need of a function that when passed in a string it counts the dashes(-), spaces ( ) and apostrophe’s (‘) and returns a count.  
ie I pass in a string of:

RED-CAR        it would return 1
F O X Y      it would return 3
A-TX’N      it would return 2
MY 69’ GTO      it would return 3
 
Any great ideas?
us1975mcAsked:
Who is Participating?
 
strickddConnect With a Mentor Commented:
Public Function GetCount(ByVal val As String) As Integer
    return val.Split(" -'".ToCharArray()).Length 'You may need to subtract 1 here
End Function
0
 
käµfm³d 👽Commented:
Sure:

int occurrences = System.Text.RegularExpressions.Regex.Matches(input, "[- ’]").Count;

Open in new window

0
 
käµfm³d 👽Commented:
Change the "int occurrences" to "Dim occurrences As Integer" and remove the semi-colon in my example. I didn't notice that it was for VB  : \
0
 
us1975mcAuthor Commented:
Sorry that it took so long.  I stepped out and just returned and it works fine with the -1.

Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.