Geeks With Blogs

Geekus Con Livus Malcolm Anderson's home for Geeks With Lives

All I wanted was to take a numeric string, and increment it.  The string happened to be 2 digits long.

All I wanted to do was something along the lines of var.ToString().PadLeft(2).

So off to google I went, and I finally found my answer, but not in any MSDN documentation.  The MSDN docs refer to format strings as if I use them EVERY single day.  I don't.  I deal with them about once every 3 months, (but this time ... I'm writing it down)


I eventually found this method

stringVar = intVar.ToString().PadLeft( 2, '0' );

Anyway, I finally found this on SteveX's blog which is what I wanted in the first place.

stringVar = intVar.ToString("00");


Yes, I'm hard coding it to two digits, I know, “bad programmer“.  I can hack it to length later, I just didn't want to have to write “leading zero code.

Posted on Tuesday, July 5, 2005 5:02 PM Stupid Code Tricks | Back to top

Comments on this post: Was it that hard to document?

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

Copyright © Malcolm Anderson | Powered by: