zoukankan      html  css  js  c++  java
  • 过滤HTML字符显示摘要

    public static string GetSummary(string html, int summaryLength)
        
    {
            
    string text = GetHtmlText(html);
            text 
    = DelHTML(text);
            text 
    = Strtitle(text);
            
    if (summaryLength >= text.Length)
                
    return text;
            
    return text.Substring(0, summaryLength)+"";
        }


        
    public static string GetHtmlText(string html)
        
    {
            
    return System.Text.RegularExpressions.Regex.Replace(html, @"<[^>]*>""");
        }

        
    public static string DelHTML(string Htmlstring)//将HTML去除
        {
            

            
    return Htmlstring.Trim();
        }

        
    public static string DelWords(string strtitle)
        
    {
            
    string strContent = strtitle;
            strtitle 
    = Regex.Replace(strContent, "(<H1.*?>|</H1>|</br>|<SPAN.*?>|</SPAN>|<FONT.*?>||<o:p></o:p>)""");
            strContent 
    = strtitle;
            strContent 
    = Regex.Replace(strContent, "(<IMG.*?>)""");
            strContent 
    = Regex.Replace(strContent, "(<P.*?>)""");
            strContent 
    = Regex.Replace(strContent, "(<P>)""");
            strContent 
    = Regex.Replace(strContent, "(&nbsp;)""");
            strContent 
    = Regex.Replace(strContent, "(&rdquo;)""");
            strContent 
    = Regex.Replace(strContent, "(</P>)""");
            strContent 
    = Regex.Replace(strContent, "(</BR>)""");
            strContent 
    = Regex.Replace(strContent, "(<BR>)""");
            strContent 
    = strContent.Replace("<?xml:namespace prefix = o ns = 'urn:schemas-microsoft-com:office:office'/>""");
            
    return strtitle;
        }
  • 相关阅读:
    Android 中向本地保存图片的时候,不在图库显示
    shopfiy 二次开发之自定义 sections
    shopfiy 二次开发之条件判断
    Linux中为RabbitMQ调整文件句柄数和socket连接数
    python helium 安装使用
    python log 打印
    linux 查看服务器登录失败的ip和次数
    在阿里云WINDOWS机器上部署的JAVA SpringBoot 时不时的无效 。
    打开TLS 1.1和1.2而不影响其他协议
    美团供应链架构演进
  • 原文地址:https://www.cnblogs.com/cnaspnet/p/1216790.html
Copyright © 2011-2022 走看看