• 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);
    }
    }

  • 相关阅读:
    web前端-----第二弹CSS
    web前端-----第一弹html
    mysql数据库第三弹
    mysql数据库第二弹
    mysql数据库第一弹
    django
    mysql基础
    面向对象进阶
    继承、多态、多态性
    面向对象的程序设计
  • 原文地址:https://www.cnblogs.com/lidj/p/3636177.html
Copyright © 2020-2023  润新知