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
Solved

Using lambda or Linq to split a string

Posted on 2013-06-01
3
1,311 Views
Last Modified: 2013-06-01
Hi,

need some help trying to split strings that look something like the following:

aaa_bbb_F0001
ccc_ddd_eee_Y0005

Using Linq or a lambda expression, how I can turn it into somethign like the following:

aaa_bbb_F0001  becomes F0001
ccc_ddd_eee_Y0005 become Y0005

the number of underscores varies from string to string.

thanks
0
Comment
Question by:yechan
  • 2
3 Comments
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 39213041
Hi yechan;

This should do what you need.

string inputStr = "ccc_ddd_eee_Y0005";
string result = inputStr.Split('_').LastOrDefault();

Open in new window

0
 
LVL 1

Author Comment

by:yechan
ID: 39213054
Thank you Fernando.  Works great.
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 39213056
Not a problem yechan, glad I was able to help.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Keyboard 2 41
Firing an ASP.NET event on selection of a JQuery datepicker 4 30
tableview is not updating 1 20
Dynamics CRM Plugin Query TotalRecordCount returning -1 13 44
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

828 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