- Dictionary<char, int> dic = new Dictionary<char, int>();
- string str = "Hello World";
- for (int i = 0; i < str.Length; i++)
- {
- if (str == ' ')
- {
- continue;
- }
- if (dic.ContainsKey(str))
- {
- dic[str]++;
- }
- else
- {
- dic[str] = 1;
- }
- }
- foreach (KeyValuePair<char,int> kv in dic)
- {
- Console.WriteLine("小写字母{0}出现了{1}次",kv.Key,kv.Value);
- }
- Console.ReadKey();
复制代码 |