#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
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
match .Groups["word"].Value;
好象都可以吧
{
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放到一个数组里面?
(int i = 1; i < mc.Count+1 ; i++)
-->
(int i = 0; i < mc.Count-1 ; i++)
for(int i=0;i<xx.count;i++)
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;
}
I've Got it!!
string[] arrStr = new string[] { };
string[] arrStr = new string[30];