// 实现字符串“123456456” 中有1个1,1个2....2个9
static void Main(string[] args)
{
string str = "12345689789";
f(str);
}
static Dictionary<string, int> f(string s)
{
Dictionary<string, int> dic = new Dictionary<string, int>();
while (true)
{
var length = s.Length;
if (length == 0)
{
return dic;
}
var temp = s[0];
s = Regex.Replace(s, temp.ToString(), "");
dic[temp.ToString()] = length - s.Length;
}
}
C# 统计字符串A包含B的个数
最新推荐文章于 2023-01-06 11:49:18 发布