首页 新闻 会员 周边

请教动态截取字符串的问题

0
悬赏园豆:5 [已解决问题] 解决于 2010-04-26 09:13

请问。。。有这样一个字符串。。<span style='width:300px;display:inline-block;overflow:hidden'>特殊产品提示:需要K位,低3折出票  限数量出售</span>


<span>....</span>字符是动态从字符串获取,怎么获取不包括<span></span>的字符串。。只要 ‘特殊产品提示:需要K位,低3折出票  限数量出售’这样的字符。。。谢谢

lovemc的主页 lovemc | 初学一级 | 园豆:13
提问于:2010-04-22 13:55
< >
分享
最佳答案
0

哈哈 刚刚弄了一个这样的

代码
public static string FilterHTML(string html)
{
if (html == null)
return "";
System.Text.RegularExpressions.Regex regex1
= new System.Text.RegularExpressions.Regex(@"<script[\s\S]+</script *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex2
= new System.Text.RegularExpressions.Regex(@" href *= *[\s\S]*script *:", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex3
= new System.Text.RegularExpressions.Regex(@" on[\s\S]*=", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex4
= new System.Text.RegularExpressions.Regex(@"<iframe[\s\S]+</iframe *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex5
= new System.Text.RegularExpressions.Regex(@"<frameset[\s\S]+</frameset *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex6
= new System.Text.RegularExpressions.Regex(@"\<img[^\>]+\>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex7
= new System.Text.RegularExpressions.Regex(@"</p>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex8
= new System.Text.RegularExpressions.Regex(@"<p>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex9
= new System.Text.RegularExpressions.Regex(@"<[^>]*>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
html
= regex1.Replace(html, ""); //过滤<script></script>标记
html = regex2.Replace(html, ""); //过滤href=javascript: (<A>) 属性
html = regex3.Replace(html, " _disibledevent="); //过滤其它控件的on...事件
html = regex4.Replace(html, ""); //过滤iframe
html = regex5.Replace(html, ""); //过滤frameset
html = regex6.Replace(html, ""); //过滤frameset
html = regex7.Replace(html, ""); //过滤frameset
html = regex8.Replace(html, ""); //过滤frameset
html = regex9.Replace(html, "");
html
= html.Replace(" ", "");
html
= html.Replace("</strong>", "");
html
= html.Replace("<strong>", "");
return html;
}
收获园豆:5
scai | 初学一级 |园豆:30 | 2010-04-22 14:10
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册