Solved

Using lambda or Linq to split a string

Posted on 2013-06-01
3
1,247 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 62

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 62

Expert Comment

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

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video discusses moving either the default database or any database to a new volume.

760 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now