// string word = "AAABBCDEFFFFFGGHHIIIIIIIIII";
publicvoid CountChar(string word)
{
string result = string.Empty;
(from c in word.ToCharArray()
group c by c into g
select new
{
chr = g.Key,
count = g.Count()
}).ToList().ForEach(c => result = string.Format("{0}{1}{2}", result, c.chr.ToString(), c.count.ToString()));
return result;
}
Date :
2012-07-24 09:39:06
By :
อิอิ
No. 2
Guest
เขียนผิดไปนิดนึง อิอิ
Code (C#)
// string word = "dfgghgsafsadgdfklgjsdiavjkjerljj";
public string CountChar(string word)
{
string result = string.Empty;
(from c in word.ToCharArray()
group c by c into g
select new
{
chr = g.Key,
count = g.Count()
}).ToList().ForEach(c => result = string.Format("{0}{1}{2}", result, c.chr.ToString(), c.count.ToString()));
return result;
}
ถามเพิ่มได้ปะครับ
ถ้าจะ order by ตัวอักษร ทำได้ปะครับ
Date :
2012-07-24 12:12:05
By :
mixarstudio
No. 12
Guest
Code (C#)
(from c in word.ToCharArray()
group c by c into g
orderby g.Key
select new
{
chr = g.Key,
count = g.Count()
}).ToList().ForEach(c => result = string.Format("{0}{1}{2}", result, c.chr.ToString(), c.count.ToString()));