[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 468
  • Last Modified:

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

0
hankknight
Asked:
hankknight
  • 2
  • 2
1 Solution
 
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
 
käµfm³d 👽Commented:
Sorry, add ".Value" to the end of that.
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

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now