2008-06-06 利用ASP.NET的string.PadLeft()方法來將流水號做補零的動作 20730 0 ASP.NET 最近看到ASP.NET的string有這個PadLeft()的方法..還不錯用.. 這個方法可以將流水號做補零的動作,小弟就做一個demo紹介如何使用.. 最近看到ASP.NET的string有這個PadLeft()的方法..還不錯用..這個方法可以將流水號做補零的動作,小弟就做一個demo紹介如何使用..asp.net(c#)TestPadLeft.aspx<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TestPadLeft.aspx.cs" Inherits="TestPadLeft" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>TestPadLeft</title> </head> <body> <form id="form1" runat="server"> <div> 開頭:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br /> 流水號:<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br /> 長度:<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox><br /> 補字元:<asp:TextBox ID="TextBox4" runat="server"></asp:TextBox><br /> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="執行" /></div> </form> </body> </html>TestPadLeft.aspx.csusing System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Text; public partial class TestPadLeft : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { StringBuilder sb = new StringBuilder(); sb.Append(this.TextBox1.Text); sb.Append(this.TextBox2.Text.PadLeft(int.Parse(this.TextBox3.Text),Convert.ToChar(this.TextBox4.Text))); Response.Write(sb.ToString()); } }執行結果: PadLeftASP.NETstring 回首頁