string QuestionUrl = "dsgsdaztx008fdghdfhaztx008";输出aztx008这组字符出现的次数???应该是输出2次的阿!

解决方案 »

  1.   

                string QuestionUrl = "dsgsdaztx008fdghdfhaztx008";
                System.Text.RegularExpressions.MatchCollection m = System.Text.RegularExpressions.Regex.Matches(QuestionUrl, "aztx008");
                MessageBox.Show(m.Count.ToString());
      

  2.   

    方法有很多,列出两种,还可以用其它String类方法,也可以用正则//方法一
    string QuestionUrl = "dsgsdaztx008fdghdfhaztx008";
    int count = (QuestionUrl.Length - QuestionUrl.Replace("aztx008", "").Length) / "aztx008".Length;
    //方法二
    string QuestionUrl = "dsgsdaztx008fdghdfhaztx008";
    int count = QuestionUrl.Split(new string[] { "aztx008" }, StringSplitOptions.None).Length - 1;