如何切割一段没有规律的字符串?
比如,我获取某个网页页面的源文件,需要获取里面新闻列表的标题和时间。
[解决办法]
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";//时间}