日期:2014-05-17  浏览次数:20419 次

外面传进来的参数不能用,而方法里的却能用,不知道为什么?
代码如下:
 private ArrayList GrabUrl(string url,String rule1,string rule2)
     {   string pat = @"\w*<ul\sid=""list1""\sclass=""news_list"">[\s\S]*<ul\sid=""list2\w*";
         //string pat = rule1;
         Response.Write("<textarea rows='3' cols='100'>" +rule2+ "</textarea></br>");
         string functionReturnValue = null;
         WebClient wc = new WebClient();
         try
         {  
         Stream s = wc.OpenRead("http://www.ithome.com");
         StreamReader sr = new StreamReader(s, System.Text.Encoding.GetEncoding("GB2312"));
             functionReturnValue = sr.ReadToEnd();
             s.Close();
             wc.Dispose();
         }
         catch (Exception ex)
         {
             functionReturnValue = ex.Message;
         }
         Regex reg = new Regex(pat, RegexOptions.IgnoreCase);//查找所需新闻内容的链接的区块
         Match news = reg.Match(functionReturnValue);
         Regex regex = new Regex(rule2);//过滤出新闻链接
         ArrayList listNew = new ArrayList();
         Match match = regex.Match(news.Value);
         while (match.Success)
         {
             //Response.Write(match.Value+"</br>");
             //String str_href =match.Value;
             listNew.Add(match.Value);
             //href_str = str_href + "|";
             match=match.NextMatch();
         }
         return listNew; 
     }

如果调用方法里的pat参数能到达所需效果,但是外部传进来的rule1参数却得不到想要的结果,pat参数里的内容和rule1里的内容是一样的。
各位大哥帮忙看看问题到底出在哪??
(rule1=@"\w*<ul\sid=""list1""\sclass=""news_list"">[\s\S]*<ul\sid=""list2\w*";rule2=@"href[^\s]*")
------最佳解决方案--------------------
(string url,String rule1,string rule2)
其中第二个参数类型错了,你改为小写的string看下
------其他解决方案--------------------
用p