zoukankan      html  css  js  c++  java
  • C#将html代码转换成文本代码

     1 /// <summary>
     2     /// 去除HTML标记 
     3     /// </summary>
     4     /// <param name="strHtml">包括HTML的源码 </param>
     5     /// <returns>已经去除后的文字</returns>
     6     public static string StripHTML(string strHtml)
     7     {
     8         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+);", @"-->", @"<!--.*
    " };
     9         string[] aryRep = { "", "", "", """, "&", "<", ">", " ", "xa1", "xa2", "xa3", "xa9", "", "
    ", "" };
    10         string newReg = aryReg[0];
    11         string strOutput = strHtml;
    12         for (int i = 0; i < aryReg.Length; i++)
    13         {
    14             Regex regex = new Regex(aryReg[i], RegexOptions.IgnoreCase);
    15             strOutput = regex.Replace(strOutput, aryRep[i]);
    16         }
    17         strOutput.Replace("<", ""); strOutput.Replace(">", "");
    18         strOutput.Replace("
    ", ""); return strOutput;
    19     }
  • 相关阅读:
    反转链表
    链表中倒数第k个结点
    调整数组顺序使奇数位于偶数前面
    词根词缀,非核心prefix/suffix/root
    核心过去式/过去完成时Past tense / past perfect
    非顺序表达
    英语连读
    图片,视频总结
    sql,explain
    @transaction注解
  • 原文地址:https://www.cnblogs.com/myselfyourself/p/3992839.html
Copyright © 2011-2022 走看看