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

i am triying to split a string starts with lower letter to end.

Example:
ABCd;d6523;SiBABC.R;s1;EEcUY

i can split these string with ";" after that i have an array like

arr[]={"ABDd","d6523","SiBABC.R","s1","EEcUY"}

then i want to get value after lower lettters like;
6523,BABC.R,1,UY

or

EFGi;ABo00004;SEg1004;s4

00004,1004,4

below i have tried something but, it fails when it tries to get value of TagName=d
it finds "ABCd", but i expect to get "6523"

Do you have any idea ? or Can you suggest me to search any document for that?

What I have tried:

C#
string txtLine="ABCd;d6523;SiBABC.R;s1;EEcUY";
string[] TagName = new string[] { "d", "Si", "s", "EEc" };
var arr = txtLine.Split(';');

 foreach (var item in TagName)
            {
               
                var val = array.Where(m => m.IndexOf(item) > -1).FirstOrDefault().Substring(item.Length);
                
            }
Posted
Updated 10-Oct-17 1:29am

1 solution

Try a regex:
(?<=[a-z])(?<Value>[^a-z;]+?)(?=[a-z;]|$)

C#
string txtLine = "ABCd;d6523;SiBABC.R;s1;EEcUY";
MatchCollection matches = Regex.Matches(txtLine, @"(?<=[a-z])(?<Value>[^a-z;]+?)(?=[a-z;]|$)");
foreach (Match m in matches)
    {
    Console.WriteLine(m.Value);
    }
Generates:
6523
BABC.R
1
UY
 
Share this answer
 
Comments
Member 13454019 10-Oct-17 7:40am    
thanks, you gave me the fish. After now i will learn how to fish :)
OriginalGriff 10-Oct-17 8:00am    
"If you give a man a fish, he will eat for a day. If you teach a man to fish, you'll never get another days' work out of him because he'll be out on the river until sundown."

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