?
Solved

Using lambda or Linq to split a string

Posted on 2013-06-01
3
Medium Priority
?
1,408 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
[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
3 Comments
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

801 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