C#生成编号不够位往前补零
示例代码:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace TestToString0000 { class Program { static void Main(string[] args) { String headStr = "YYCC"; int curNumber =1; String applyOrdeNo = headStr + curNumber.ToString("00000"); Console.WriteLine(applyOrdeNo); curNumber = 1234; applyOrdeNo = headStr + curNumber.ToString("00000"); Console.WriteLine(applyOrdeNo); curNumber = 12345; applyOrdeNo = headStr + curNumber.ToString("00000"); Console.WriteLine(applyOrdeNo); Console.ReadKey(); } } }
运行结果:
YYCC00001
YYCC01234
YYCC12345
以上演示了,生成一个编号,当位数不够时,进行补零操作。
保证所有编号的长度是相等的。