当前位置:编程学习 > C#/ASP.NET >>

asp.net里面删除去掉多余的空格和换行符号源码

站长资源库免登录,轻松复制自己需要的源代码:
asp.net里面删除不需要多余的空格和换行符函数

using System;  
using System.Data;  
using System.Configuration;  
using System.Web; 
using System.Web.Security;  
using System.Web.UI;  
using System.Web.UI.WebControls;  
using System.Web.UI.HtmlControls; 
using System.Text.RegularExpressions;  
using System.IO;   
/// <summary>  
/// PageBase 页面基类 
/// </summary>  
public class PageBase : System.Web.UI.Page  
{      
 protected override void Render(HtmlTextWriter writer)      
 {         
  StringWriter sw = new StringWriter();          
  HtmlTextWriter htmlWriter = new HtmlTextWriter(sw);          
  base.Render(htmlWriter);          
  string html = sw.ToString();          
  html = Regex.Replace(html, "[\f\n\r\t\v]", "");          
  html = Regex.Replace(html, " {2,}", " ");          
  html = Regex.Replace(html, ">[ ]{1}", ">");          
  writer.Write(html);      
 }  

}


ar msg = obj.ToString();
msg = Regex.Replace(msg, @"[\r\n]", "");    // 注意是:\r\n 


C# 删除换行符
换行符

.Replace("\n","").Replace(" ","").Replace(”\t", "").Replace("\r","");

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,