?
Solved

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

Posted on 2013-01-13
4
Medium Priority
?
454 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
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…
Suggested Courses

771 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