zoukankan      html  css  js  c++  java
  • asp.net页面过滤所有换行符和多余空格

    不知道大家注意到了没有,Google和Baidu网页的HTML源代码是混合在一起的。HTML代码混合在一起,出发点是为了减小网页体积,从而加快网页加载速度。

          写个函数把网页HTML源代码的换行符和空格过滤掉其实并不难,我这里是写了个基类,在asp.net编程时,页面只要继承这个基类,那么输出的HTML代码就会自动去掉换行符,和多余的空格符号,例如“> <”之间的空格符号。

     

     

    usingSystem;
    usingSystem.Data;
    usingSystem.Configuration;
    usingSystem.Web;
    usingSystem.Web.Security;
    usingSystem.Web.UI;
    usingSystem.Web.UI.WebControls;
    usingSystem.Web.UI.HtmlControls;
    usingSystem.Text.RegularExpressions;
    usingSystem.IO;
    /// <summary>
    /// PageBase 页面基类
    /// </summary>
    publicclassPageBase:System.Web.UI.Page
    {
    protectedoverridevoidRender(HtmlTextWriter writer)
    {
    StringWriter sw =newStringWriter();
    HtmlTextWriter htmlWriter =newHtmlTextWriter(sw);
    base.Render(htmlWriter);
    string html = sw.ToString();
    html =Regex.Replace(html,"[f v]","");
    html =Regex.Replace(html," {2,}"," ");
    html =Regex.Replace(html,">[ ]{1}",">");
    writer.Write(html);
    }
    }

  • 相关阅读:
    os模块
    自定义模块--->可执行文件
    VSCode同步插件Sync
    Django之模板
    十:索引+慢查询
    八分组查询
    (一)Django之虚拟环境
    二:Anaconda的使用
    Python之数据类型
    Python零散知识点
  • 原文地址:https://www.cnblogs.com/lidj/p/3636177.html
Copyright © 2011-2022 走看看