class Program
{
static void Main(string[] args)
{
//統計出字符串中,下雪出現的次數,并每次出現的索引位置;
string text = "今天下雪了嗎,明天不會下雪了吧,什么時候才不下雪啊,我要去上學啊!";
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("下雪出現的總次數:{0}",count);
Console.ReadKey();
}
}