当前位置: 代码迷 >> ASP.NET >> ASP.NET怎么去掉HTML字符串中的HTML标签
  详细解决方案

ASP.NET怎么去掉HTML字符串中的HTML标签

热度:9775   发布时间:2013-02-25 00:00:00.0
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);
            }

------其他解决方案--------------------------------------------------------
http://blog.csdn.net/gulijiang2008/article/details/7190281
------其他解决方案--------------------------------------------------------
这个用HtmlAgilityPack会非常简单。
------其他解决方案--------------------------------------------------------

public static string ReplaceHtmlMark(string HtmlString)
        {
            string[] RegexString = {
                                       @"style='.*?'",
                                       @"class='.*?'",
                                       @"<param.*?>(</param>)?",
                                       @"<embed.*?>(</embed>)?",
                                       @"<object.*?>(</object>)?",
                                       @"<strong.*?>(</strong>)?",
                                       @"<span.*?>(</span>)?",
                                       @"<p.*?>(</p>)?",
  相关解决方案