class Program
{
static void Main(string[] args)
{
//統(tǒng)計出字符串中,下雪出現(xiàn)的次數(shù),并每次出現(xiàn)的索引位置;
string text = "今天下雪了嗎,明天不會下雪了吧,什么時候才不下雪啊,我要去上學(xué)啊!";
string keyWord = "下雪";
int index = 0;
int count = 0;
while ((index=text.IndexOf(keyWord,index))!=-1)
{
count++;
Console.WriteLine("第{0}次;索引是{1}",count,index);
index =index+ keyWord.Length;
}
Console.WriteLine("下雪出現(xiàn)的總次數(shù):{0}",count);
Console.ReadKey();
}
}