Seriously; Not sure what you really wanted but I saw a challenge so; this should do the trick.
public IEnumerable<Pair> CountThat(string data)
{
var result = new List<Pair>();
var lines = new List<string>(data.Split(new [] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries));
lines = lines.Where(x => !x.Contains('-') && !x.Contains('*')).ToList();
double id = 0;
foreach (var line in lines)
{
var item = line.Replace("\t", " ");
var sections = new List<string>(item.Split(new []{' '}, StringSplitOptions.RemoveEmptyEntries));
if (sections.Count > 1)
{
if (!double.TryParse(sections[0], out id))
id = 0;
int panel;
if (!int.TryParse(sections[1], out panel))
panel = 0;
if ((id != 0) && (panel != 0))
{
var pair = new Pair {Key = (int) id, Value = panel};
if(!result.Contains(pair))
result.Add(pair);
}
}
else
{
int panel;
if ((int.TryParse(sections[0], out panel)) &&
(0 != id) )
{
var pair = new Pair {Key = (int) id, Value = panel};
if (!result.Contains(pair))
result.Add(pair);
}
}
}
return result;
}
then go over the result like:
foreach (var key in result.Select(x => x.Key).Distinct())
{
int closure = key;
int count = result.Count(x => x.Key == closure);
Console.WriteLine(closure + " has " + count + " panels");
}
I somehow get the feeling that I'm doing your homework....
If this works for you, upvote it, accept the answer and be happy.
Regards, AT