首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

c# 正则循环异常 麻烦帮看看 速结

2012-11-10 
c# 正则循环错误 麻烦帮看看 速结for (int i 0 i 10 i++){MatchCollection mc Regex.Matches(html

c# 正则循环错误 麻烦帮看看 速结

  for (int i = 0; i < 10; i++)
  {
  MatchCollection mc = Regex.Matches(html, @"<li class=['""]top-"+i+"['""]>(?<text>[\s\S]*?)</li>", RegexOptions.IgnoreCase);
  string chulihtml = "";
  foreach (Match m in mc)
  {

  chulihtml = m.Groups["text"].Value;
  break;
  }
  }
这个位置 不对top-"+i+"

如果想循环的话 怎么写呢?

[解决办法]
修改下 

C# code
Regex re = new Regex(@"<li class=['\""]top-\d['\""]>(?<text>[\s\S]*?)</li>", RegexOptions.None);MatchCollection mc = re.Matches("text");foreach (Match ma in mc){}
[解决办法]
这样 
MatchCollection mc = Regex.Matches(html, @"<li class=['""]top-"+i.ToString()+@"['""]>(?<text>[\s\S]*?)</li>", RegexOptions.IgnoreCase);

热点排行