Solved

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

Posted on 2013-01-13
4
437 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 74

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 74

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…

743 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

8 Experts available now in Live!

Get 1:1 Help Now