日期:2014-05-19  浏览次数:20473 次

格式显示的问题,大家帮忙呀,小妹我急

我想在首页显示某个内容的摘要,但内容是html格式的,比如:提取前20个字,这20个字可能全是html代码,结果一个汉字也不显示。应该如何显示20个文字,而过滤过html代码。谢谢!

------解决方案--------------------
正则过滤后在输出
------解决方案--------------------
string yourStr = " <table> <tr> <td> adfadf </td> </tr> </table> <hr> ";
string resultStr = System.Text.RegularExpressions.Regex.Replace(yourStr, @ " <[\s\S]*?> ", " " , System.Text.RegularExpressions.RegexOptions.IgnoreCase);
Response.Write(resultStr.Substring(0,4));
------解决方案--------------------
正则表达
------解决方案--------------------
晚了点.呵呵
System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(@ " <[^> ]*> ", System.Text.RegularExpressions.RegexOptions.IgnoreCase);

string str12 = regex.Replace( " <td height= '56 ' align= 'left> <a href= 'http://community.csdn.net/ ' target= '_blank '> <span class= 'style2 '> 我要去社区 </span> <img src= '/images/hot_2.gif ' width= '30 ' height= '9 ' border= '0 '> </a> <a href= 'http://dev.csdn.net ' target= '_blank '> <span class= 'style2 '> 我要找文档 ", " ");