Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Using lambda or Linq to split a string

Posted on 2013-06-01
3
Medium Priority
?
1,470 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 64

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 64

Expert Comment

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

Featured Post

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

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…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

636 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