日期:2014-05-18 浏览次数:21232 次
void Main()
{
string str=@"[aaaa]11[bbbbb]
.....
[aaaa]12[bbbbb]
......
..
[aaaa]13[bbbbb]
.....";
var arrstr=GetJieQuAll("[aaaa]","[bbbbb]",str); //得到null了
Console.WriteLine(arrstr);
}
public string[] GetJieQuAll(string start, string end, string html)
{
Regex regstr = new Regex(Regex.Escape(start) + @"([\s\S]*?)" + Regex.Escape(end));
MatchCollection mc = regstr.Matches(html);
if (mc.Count > 0)
{
string[] strstring = new string[mc.Count];
int i = 0;
foreach (Match m in mc)
{
strstring[i] = m.Groups[1].Value;
i++;
}
return strstring;
}
return null;
}
------解决方案--------------------
public static string[] GetJieQuAll(string start, string end, string html)
{
Regex regstr = new Regex(Regex.Escape(start) + @"([\s\S])*?" + Regex.Escape(end));
MatchCollection mc = regstr.Matches(html);
if (mc.Count > 0)
{
string[] strstring = new string[mc.Count];
int i = 0;
foreach (Match m in mc)
{
string s = Regex.Replace(m.Groups[0].ToString(), Regex.Escape(start).ToString(), "");
s = Regex.Replace(s, Regex.Escape(end).ToString(), "");
strstring[i] = s;
++i;
}
return strstring;
}
return null;
}
------解决方案--------------------