Does anybody know how to create padded string formatting when dealing with numerics?
In C++ you would write printf("%08ld",123), and you would get "00000123", but I can't find an equivalent with String.Format("{0}",123)
As powerful as they claim their new formatting stuff to be, I cannot find out what the format string is to do the same with C#.
Any ideas?
Cheers,
Tom
I am not young enough to know everything - Oscar Wilde
I was edit happy, so maybe you were referring to an older version of what I had, but String.Format("{0:00000000}",123) and lNum.ToString("00000000") both work. (Just tested them in a console app.)
If you use the {0:D8} format specification, just be sure to have an integer (or another numeric data type) as argument. If you pass a string, it will not work.
Bookmarks