1.C#String.IndexOf检索字符串中字符出现的次数
string str = "Hello, please come to my office the afternoon";
string s = "o";
int Star = 0;
int Count = 0;
while (Star != -1)
{
Star = str.IndexOf(s, Star);//获取字符的索引
if (Star != -1)
{
Count++;
Star++;
}
}
Console.WriteLine(Count.ToString());
Console.ReadKey();
注:本文整理自网络!!!