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

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

LVL 16
hankknightAsked:
Who is Participating?
 
käµfm³d 👽Connect With a Mentor Commented:
Sorry, add ".Value" to the end of that.
0
 
käµfm³d 👽Commented:
Try:

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

Open in new window

0
 
hankknightAuthor Commented:
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
 
hankknightAuthor Commented:
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
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.