zoukankan      html  css  js  c++  java
  • C#内容格式刷html 转成txt

    /// <summary>

            /// 内容格式刷

            /// </summary>

            /// <param name="strHtml">要格式的文本</param>

            /// <returns></returns>

            public static string HtmlToTxt(string strHtml)

            {

                string[] aryReg ={

                @"<script[^>]*?>.*?</script>",

                @"<(/s*)?!?((w+:)?w+)(w+(s*=?s*(([""'])(\[""'tbnr]|[^7])*?7|w+)|.{0})|s)*?(/s*)?>",

                @"([ ])[s]+",

                @"&(quot|#34);",

                @"&(amp|#38);",

                @"&(lt|#60);",

                @"&(gt|#62);", 

                @"&(nbsp|#160);", 

                @"&(iexcl|#161);",

                @"&(cent|#162);",

                @"&(pound|#163);",

                @"&(copy|#169);",

                @"&#(d+);",

                @"-->",

                @"<!--.* "

                };

                string newReg = aryReg[0];

                string strOutput = strHtml;

                for (int i = 0; i < aryReg.Length; i++)

                {

                    Regex regex = new Regex(aryReg[i], RegexOptions.IgnoreCase);

                    strOutput = regex.Replace(strOutput, string.Empty);

                }

                strOutput.Replace("<", "");

                strOutput.Replace(">", "");

                strOutput.Replace(" ", "");

                return strOutput;

            }

  • 相关阅读:
    清除微信浏览器缓存
    JS实现HTML标签转义及反转义
    mvc中服务器端、客户端属性验证
    Ajax.ActionLink参数详解
    Ajax.BeginForm参数详解
    AjaxHelper简介
    将博客搬至CSDN
    Sequelize小记
    端口: 查看端口状态
    搭建git服务器
  • 原文地址:https://www.cnblogs.com/ken-admin/p/6405762.html
Copyright © 2011-2022 走看看