Solved

ASP.NET / VB / REGEX: Everything After Last Comma

Posted on 2013-01-13
4
441 Views
Last Modified: 2013-01-13
How can I get everything after the last comma in a string?

This does NOT work:
dim Address as String = "Madison, WI"
dim State = Address.EverythingAfterLastComma.Trim
Response.Write(State)

Open in new window

0
Comment
Question by:hankknight
  • 2
  • 2
4 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 38772541
Try:

Dim result As String = Regex.Match(original, "[^,]+$").Groups(0)

Open in new window

0
 
LVL 16

Author Comment

by:hankknight
ID: 38772549
Dim original As String = "City, XZ"
Dim result As String = Regex.Match(original, "[^,]+$").Groups(0)

Open in new window

I get this error:
Compiler Error Message: BC30311: Value of type 'System.Text.RegularExpressions.Group' cannot be converted to 'String'.
0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 38772569
Sorry, add ".Value" to the end of that.
0
 
LVL 16

Author Comment

by:hankknight
ID: 38772579
Thanks, this works:

Dim original As String = "City, XZ"
Dim result As String = Regex.Match(original, "[^,]+$").Groups(0).Value.Trim

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

929 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

11 Experts available now in Live!

Get 1:1 Help Now