Based on your description, it seems like it might be possible that the strings are not guaranteed to be consistent. The following code will construct a List<String>
of delimited (parsed) lines based on an incoming list of unknown content. It's a bit of a "brute force" method, but should allow for flexibility in the incoming list. Here is the code:
List<String> list = new List<String>();
list.Add("full1");
list.Add("full1inc1");
list.Add("full1inc2");
list.Add("full1inc3");
list.Add("full2");
list.Add("full2inc1");
list.Add("full2inc2");
list.Add("full3");
List<String> lines = new List<String>();
foreach (String str in list)
{
String tmp = String.Empty;
StringBuilder sb1 = new StringBuilder();
StringBuilder sb2 = new StringBuilder();
foreach (Char ch in str.ToCharArray())
{
if (Char.IsLetter(ch))
{
if (!String.IsNullOrEmpty(sb2.ToString()))
{
tmp += sb2.ToString() + ",";
sb2 = new StringBuilder();
}
sb1.Append(ch);
}
else
{
if (!String.IsNullOrEmpty(sb1.ToString()))
{
tmp += sb1.ToString() + ",";
sb1 = new StringBuilder();
}
sb2.Append(ch);
}
}
if (!String.IsNullOrEmpty(sb1.ToString()))
tmp += sb1.ToString() + ",";
if (!String.IsNullOrEmpty(sb2.ToString()))
tmp += sb2.ToString() + ",";
lines.Add(tmp);
for (Int32 i = 0; i < lines.Count; i++)
lines[i] = lines[i].TrimEnd(',');
}
So, based on your example list, here's what you will get:
full1 --> "full,1"
full1inc1 --> "full,1,inc,1"
full1inc2 --> "full,1,inc,2"
full1inc3 --> "full,1,inc,3"
full2 --> "full,2"
full2inc1 --> "full,2,inc,1"
full2inc2 --> "full,2,inc,2"
full3 --> "full,3"
full100inc100 --> "full,100,inc,100"
With this method, you will not need to presume that "full" is the leading string, or that it is followed by "inc" (or really anything at all).
Once you have the resulting delimited list, and because you know that the pattern is StringNumberStringNumber
, you can then use whatever means you like to split those delimited lines into pieces and use them as you like.