string str = "两只老虎,两只老虎,跑得快,跑得快。一只没有耳朵,一只没有尾巴,真奇怪,真奇怪。";
Dictionary<char, int> dic = new Dictionary<char, int>();
for (int i = 0; i < str.Length; i++)
{
if (!dic.ContainsKey(str[i]))
{
dic.Add(str[i], 1);
}
else {
dic[str[i]]++;
}
}
foreach (KeyValuePair<char,int> item in dic)
{
Console.WriteLine("字符{0}出现了{1}次",item.Key,item.Value);
}
Console.ReadKey();