?
Solved

Count Dash Space and Apostrophe in string

Posted on 2011-10-20
4
Medium Priority
?
349 Views
Last Modified: 2012-05-12
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?
0
Comment
Question by:us1975mc
  • 2
4 Comments
 
LVL 28

Accepted Solution

by:
strickdd earned 2000 total points
ID: 37002837
Public Function GetCount(ByVal val As String) As Integer
    return val.Split(" -'".ToCharArray()).Length 'You may need to subtract 1 here
End Function
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 37002847
Sure:

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

Open in new window

0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 37002875
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
 

Author Closing Comment

by:us1975mc
ID: 37003335
Sorry that it took so long.  I stepped out and just returned and it works fine with the -1.

Thanks!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

862 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