using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string str = "Wasdgf eggggg2sfdgbbdh";
Dictionary<char, int> dic = new Dictionary<char, int>();
for (int i = 0; i < str.Length; i++)
{
if (str[i] == ' ')
{
continue;
}
if (dic.ContainsKey(str[i]))
{
dic[str[i]]++;
}
else
{
dic[str[i]] = 1;
}
}
foreach (KeyValuePair<char, int> kv in dic)
{
Console.WriteLine("字母{0}出现了{1}次", kv.Key, kv.Value);
}
Console.ReadKey();
}
}
}
C#统计字符串中字符出现的次数
最新推荐文章于 2023-11-27 11:35:06 发布