天天看點

C#實作數字字元串左補齊0的兩種方法

2種方法實作數字字元串的左補齊0

                int n = 3;

                string s = n.ToString().PadLeft(4, '0'); //0003

                s = string.Format("{0:d4}", n);          //0003

本文轉自 h2appy  51CTO部落格,原文連結:http://blog.51cto.com/h2appy/1171789,如需轉載請自行聯系原作者