#region "获取匹配"
     public string[] macthValue(string regexStr, string htmlStr)
     {
         MatchCollection mc;
         string[] arrStr = new string[] { };
         Regex r = new Regex(regexStr);
         mc = r.Matches(htmlStr);
         for (int i = 1; i < mc.Count+1 ; i++)
         {
             arrStr[i] = mc[i].Value;
             //MessageBox.Show("mc");
         }
         return arrStr;
     }
     #endregion

解决方案 »

  1.   

    不过,我尝试将arrStr[i]=mc[i].Value;注释掉,用下面的MSGbox,却能正确Show出来,数一数,数字也对。
      

  2.   

    foreach (Match match in mc)match .Groups[i].Value;
    match .Groups["word"].Value;
    好象都可以吧
      

  3.   

    public string[] macthValue(string regexStr, string htmlStr) 
         { 
             MatchCollection mc; 
             string[] arrStr = new string[] { }; 
             Regex r = new Regex(regexStr); 
             mc = r.Matches(htmlStr); 
             for (int i = 0; i  < mc.Count ; i++) 
             { 
                 arrStr[i] = mc[i].Value; 
                 //MessageBox.Show("mc"); 
             } 
             return arrStr; 
         } 
         #endregion
    数组下标从0开始。
    另外,为什么把MatchCollection放到一个数组里面?
      

  4.   

    索引从0开始的
    (int i = 1; i  < mc.Count+1 ; i++)
    -->
    (int i = 0; i  < mc.Count-1 ; i++)
      

  5.   

    边界,养成个习惯
    for(int i=0;i<xx.count;i++)
      

  6.   

    ft仔细看了一眼,你建立数组的时候根本就没有声明数组的大小。
    public string[] macthValue(string regexStr, string htmlStr) 

        MatchCollection mc; 
        Regex r = new Regex(regexStr); 
        mc = r.Matches(htmlStr); 
        int count = mc.Count;
        string[] arrStr = new string[count]();     
        
        for (int i = 0; i  < count ; i++) 
        { 
            arrStr[i] = mc[i].Value; 
             //MessageBox.Show("mc"); 
         } 
         return arrStr; 
    }
      

  7.   

    GOD!!!!!
    I've  Got it!!
    string[] arrStr = new string[] { }; 
    string[] arrStr = new string[30];