Code in the oven
Wednesday, August 24, 2011
Pad a string with zeros on the left/right in C# until completing n digits
Very simple way to pad with zeros until completing n digits
strMyString.PadLeft(n,'0');
Sample
string strMyString = "1234";
strMyString = strMyString.PadLeft(7,'0');
...will display "0001234"
Other notes: there is a .PadRight() function too.
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment