C#语言怎么删除<b>和</b>标签
string str="<p><b>
<table border=1>
<tbody>
<tr>
<td>标题</td>
<td>倾向性</td>
<td>点击量</td>
<td>发布时间</td></tr>
<tr>
<td>秦皇岛闹市区新建两处过街天桥</td>
<td>中性</td>
<td>25</td>
<td>2012-9-13 2:43:06</td></tr></tbody></table></b></p>";
怎么删除里面的<b>标签
[解决办法]
正则替换掉
StreamReader reader = new StreamReader("c:\\temp\\1.txt",Encoding.Default);
string source = reader.ReadToEnd();
Regex reg = new Regex(@"(?is)<b>.*?</b>");
source = reg.Replace(source, "");
public string ClearHtml(string HtmlStr)
{
string tmpStr = HtmlStr;
tmpStr = ReplaceHtml("&#[^>]*;", tmpStr, "");
tmpStr = ReplaceHtml("</?marquee[^>]*>", tmpStr, "");
tmpStr = ReplaceHtml("</?object[^>]*>", tmpStr, "");
tmpStr = ReplaceHtml("</?param[^>]*>", tmpStr, "");
tmpStr = ReplaceHtml("</?embed[^>]*>", tmpStr, "");
tmpStr = ReplaceHtml("</?table[^>]*>", tmpStr, "");
tmpStr = ReplaceHtml(" ", tmpStr, "");
tmpStr = ReplaceHtml("</?tr[^>]*>", tmpStr, "");
tmpStr = ReplaceHtml("</?th[^>]*>", tmpStr, "");
tmpStr = ReplaceHtml("</?p[^>]*>", tmpStr, "");
tmpStr = ReplaceHtml("</?a[^>]*>", tmpStr, "");
tmpStr = ReplaceHtml("</?img[^>]*>", tmpStr, "");
tmpStr = ReplaceHtml("</?tbody[^>]*>", tmpStr, "");
tmpStr = ReplaceHtml("</?li[^>]*>", tmpStr, "");
tmpStr = ReplaceHtml("</?span[^>]*>", tmpStr, "");
tmpStr = ReplaceHtml("</?div[^>]*>", tmpStr, "");
tmpStr = ReplaceHtml("</?th[^>]*>", tmpStr, "");
tmpStr = ReplaceHtml("</?td[^>]*>", tmpStr, "");
tmpStr = ReplaceHtml("</?script[^>]*>", tmpStr, "");
tmpStr = ReplaceHtml("(javascript
[解决办法]
jscript
[解决办法]
vbscript
[解决办法]
vbs):", tmpStr, "");
tmpStr = ReplaceHtml("on(mouse
[解决办法]
exit
[解决办法]
error
[解决办法]
click
[解决办法]
key)", tmpStr, "");
tmpStr = ReplaceHtml("<[^>]*>", tmpStr, "");
tmpStr = ReplaceHtml("<\\/?[a-z]+:[^>]*>", tmpStr, "");
tmpStr = ReplaceHtml("</?font[^>]*>", tmpStr, "");
tmpStr = ReplaceHtml("</?b[^>]*>", tmpStr, "");
tmpStr = ReplaceHtml("</?u[^>]*>", tmpStr, "");
tmpStr = ReplaceHtml("</?i[^>]*>", tmpStr, "");
tmpStr = ReplaceHtml("</?strong[^>]*>", tmpStr, "");
return tmpStr;
}
public string ReplaceHtml(string Pattern, string HtmlStr, string replacement)
{
System.Text.RegularExpressions.Regex rx = new System.Text.RegularExpressions.Regex(Pattern,System.Text.RegularExpressions.RegexOptions.IgnoreCase);
if(rx.IsMatch(HtmlStr))
return rx.Replace(HtmlStr, replacement);
return HtmlStr;
}