Counting words in the list Using c#
I have a list,im storing the value like
list[0]="sun"
list[1]="moon"
list[2]="Alpha"
list[3]="Sun"
list[4]="Sun"
list[5]="Moon"
i want the output like
word count
=============================
sun 3
moon 2
Alpha 1
please anyone help me to do this.
Loading
Sukesh MarlaPosted Aug 14, 2012, 1:55 AM
List list = new List();
list.Add("sun");
list.Add("moon");
list.Add("Alpha");
list.Add("Sun");
list.Add("Sun");
list.Add("Moon");
var Words=list.GroupBy(x=>x.ToLower()).Select(x=>new {asdsa=x.Key,Count=x.Count()});
Your Response is important to use. Please Check This is Currect Answer, if it helped
subrahmanyaPosted Aug 14, 2012, 2:12 AM
List
wordCount.Add("sun");
wordCount.Add("moon");
wordCount.Add("Alpha");
wordCount.Add("Sun");
wordCount.Add("Sun");
wordCount.Add("Moon");
Dictionary
for (int count = 0; count < wordCount.Count; count++)
{
List
delegate(string Name)
{
return Name.ToUpper().Equals(wordCount[count].ToUpper());
}
);
if (!display.ContainsKey(wordCount[count].ToUpper()))
{
display.Add(wordCount[count].ToUpper(), results.Count);
}
}
foreach (string item in display.Keys)
{
MessageBox.Show(item + " count = " + display[item].ToString());
}
Pavi SPosted Aug 14, 2012, 1:03 AM
it should be non case sensitive.
moon and Moon the count should 2
l[0]="moon"
l[1]="Moon"
ouput i want
=============
word count
-----------------------
Moon 2
using c#