C # Fill in zero when the number of digits is insufficient:
Int I = 10;
Method 1: console. writeline (I. tostring ("D5 "));
Method 2: console. writeline (I. tostring (). padleft (5, '0'); // recommended
Method 3: console. writeline (I. tostring ("00000 "));
In C #, you can use padleft and padright to complement strings easily.
Padleft (INT totalwidth, char paddingchar) // fill in the totalwidth length with paddingchar on the left of the string
Padleft (INT totalwidth, char paddingchar) // fill in the totalwidth length with paddingchar on the right of the string
Example:
H = H. padleft (2, '0 ');
Note that the second parameter is of the char type, so you can use single quotes or convert. tochar (string value) to convert the string to the char type. If the string length is greater than 1, str. tochararray () [Index] is used.
Source: http://www.cnblogs.com/zhangqs008/archive/2012/02/01/2341078.html
C # Zero-digit replacement