学习了一下Trim的用法,挺实用的。
前台代码:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Trimi小技巧</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtTrim" runat="server"></asp:TextBox>
<asp:Button ID="btnTrim" runat="server" Text="确定" OnClick="btnTrim_Click" />
</div>
</form>
</body>
</html>
后台代码:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class Trim : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnTrim_Click(object sender, EventArgs e)
{
char[] TrimChar = { ' ', '-', '\'', '\"', '\\' }; //此处使用了转义字符如:\',\",\\,分别表示单引号,双引号,反斜杠
txtTrim.Text = this.txtTrim.Text.Trim(TrimChar);
}
}
挺好用的,转载自:https://www.cnblogs.com/shanaihuan/archive/2011/04/13/2014565.html