Geeks With Blogs
Code.Blog Code Talk for the Game Developer

I just had to padd an integer with zeros when I displayed it and thought it would be a good piece of code to post considering there are some crazy difficult versions of doing this on the net that seem quite unnecessary.

iNum.ToString("000")

This will pad iNum with leading zeros if it's length is smaller than 3.  For example, if iNum = 42, the output would be the string "042".

HERE's a great MS resource for numerous ways to pad strings including with zeros and blank spaces (it's about padding in PowerShell but the general concepts still apply to VB, I can assume it would with C# as well).

Posted on Wednesday, August 6, 2008 10:46 AM Tutorials | Back to top


Comments on this post: ToString() Padding Zeros

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Matthew Christian | Powered by: GeeksWithBlogs.net