C#String.IndexOf检索字符串中字符出现的次数

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();

注:本文整理自网络!!!

posted on 2012-07-21 15:09  YuanSong  阅读(6769)  评论(0编辑  收藏  举报

导航