ASP.NET如何去掉HTML字符串中的HTML标签
有一段字符串类似“<OL><LI><STRONG>wwwwwww</STRONG><BR>wwwwww<BR><STRONG>wwwwwww</STRONG><BR><STRONG>
”这样的字符串,我想把这段字符串中的所有标签全部去掉,这剩下所有的wwwww,如何实现,大仙们给点指导
[最优解释]
StreamReader reader = new StreamReader("c:\\temp\\1.txt",Encoding.Default);
string source = reader.ReadToEnd();
Regex reg = new Regex(@"(?is)(?<=>)[^<]+(?=<)");
MatchCollection mc = reg.Matches(source);
foreach (Match m in mc)
{
MessageBox.Show(m.Value);
}
public static string ReplaceHtmlMark(string HtmlString)
{
string[] RegexString = {
@"style='.*?'",
@"class='.*?'",
@"<param.*?>(</param>)?",
@"<embed.*?>(</embed>)?",
@"<object.*?>(</object>)?",
@"<strong.*?>(</strong>)?",
@"<span.*?>(</span>)?",
@"<p.*?>(</p>)?",
@"<u.*?>(</u>)?",
@"<em.*?>(</em>)?",
//@"<div.*?>(</div>)?",
};
foreach (String str in RegexString)
{
Regex regex = new Regex(str, RegexOptions.IgnoreCase);
HtmlString = regex.Replace(HtmlString, string.Empty);
}
string[] RegexString2 = {
//@"</div>",
@"</p>",
@"</object>",
@"</strong>",
@"</span>",
@"</ins>",
};
foreach (String str2 in RegexString2)
{
Regex regex2 = new Regex(str2, RegexOptions.IgnoreCase);
HtmlString = regex2.Replace(HtmlString, string.Empty);
}
return HtmlString;
}