Solved

Using lambda or Linq to split a string

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

717 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