I stumbled upon this question about padding with zeros in csharp. Since it's locked and doesn't have the best answer, I decided to post this article..
This page lists the string formatting operators valid as ToString arguments. While it's not obvious, these are all also valid in String.Format()
Therefore, if this is what you need:
Input number Need
1 00000001
121 00000121
10567 00010567
You can get it by doing:
String.Format(" {0:D8}",1);
String.Format(" {0:D8}",121);
String.Format(" {0:D8}",10567);
This page lists the string formatting operators valid as ToString arguments. While it's not obvious, these are all also valid in String.Format()
Therefore, if this is what you need:
Input number Need
1 00000001
121 00000121
10567 00010567
You can get it by doing:
String.Format(" {0:D8}",1);
String.Format(" {0:D8}",121);
String.Format(" {0:D8}",10567);
Comment