Click here to Skip to main content
15,889,096 members
Please Sign up or sign in to vote.
1.00/5 (5 votes)
See more:
C#
PALINK-ID              PANELS     
1.1                      10  
                         20  
************************************
1.2                      10   
                         20  
 -----------------------------                       
2.1                      10
                         20
                         30 
--------------------------------------
2.2                      10
                         20
                         30  


i want it to split at . and count the elements in panel and return it

output :
1 has 2 panels
2 has 3 panels(based distinct values)
Posted
Updated 7-Dec-11 2:30am
v5
Comments
rajeevcapgeminiindia 24-Nov-11 22:57pm    
What are you asking for?
Please clarify your qusetion first with suitable example.
D K N T H 25-Nov-11 0:20am    
kindly define the input
Sergey Alexandrovich Kryukov 25-Nov-11 0:46am    
Makes no apparent sense. If you cannot formulate what do you want, how can you do any development?
--SA
Nasir M@hmood 25-Nov-11 1:45am    
Unclear question don't know what u want ?
Richard MacCutchan 7-Dec-11 7:36am    
Your question is still meaningless. What do you mean "1 has 2 panels"? All I see is some lines of text.

1 solution

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", " "); // not sure if you're using tab's or spaces
		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
 
Share this answer
 
v4

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