Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi everyone,

Actually, this is a very simple question. But I couldn't solve. So need your help.

I have a lot of strings like that: "2_4ad-6kss-2_5kk-3_40ppp"

Now I need to get this values from this string :

2_4
6
2_5
3_40

As you can see, everything a splitter except "_". I'm getting just numbers with Regex.
Like : 2, 4, 6, 2, 5, 3, 40
Do you have any suggestions have I can do it?


string Mystr= "2_4ad-6kss-2_5kk-3_40ppp";
string[] numbers= Regex.Split(Mystr, @"\D+");


Thank you.

What I have tried:

I tried Regex, Substring. Looking for a different way which I didn't know.
Posted
Updated 25-Nov-18 0:57am

1 solution

Try:
string Mystr = "2_4ad-6kss-2_5kk-3_40ppp";
string[] numbers = Regex.Split(Mystr, @"[^\d_]+");
 
Share this answer
 
Comments
kozmikadam 25-Nov-18 7:45am    
You are a lifesaver sir! Thank you so much.
OriginalGriff 25-Nov-18 7:53am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900