读书人

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

发布时间: 2012-11-10 10:48:51 作者: rapoo

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);

读书人网 >C#

热点推荐