日期:2014-05-18  浏览次数:20989 次

如何切割一段没有规律的字符串?
比如,我获取某个网页页面的源文件,需要获取里面新闻列表的标题和时间。

------解决方案--------------------
C# code
System.Text.RegularExpressions.Regex reg=new System.Text.RegularExpressions.Regex(@"·\s*<a[^>]*>(?<title>[^<]*)</a>\s*<font[^>]*>(?<date>[^<]*)</font>");
string result=string.Empty;
foreach(Match m in reg.Matches("你的网页代码"))
{
 result+=m.Groups["title"].Value;//新闻标题
 result+=m.Groups["date"].Value+"\r\n";//时间
}