Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C# (http://www.programmingforums.org/forum16.html)
-   -   String formatting (http://www.programmingforums.org/showthread.php?t=14331)

Arla Nov 5th, 2007 12:05 PM

String formatting
 
Okay, tried a few things and just can't get this to work, what I'm TRYING to do is write out a number formated so it's always the same number of digits, would seem simple but...

I've tried
:

int i=0;
String.Format("{0:00000000}",i.ToString());


Which just seems to produce a single 0, instead of the 8 I'd like,

I've also tried
:

int i=0;
String.Format("{0:8}",i.ToString());


Which is better because it puts in all the spaces to make it an 8 character, but still only puts a 0 as the final one, anyone have any ideas? I've tried googling it but a lot of topics explain how to make decimals appear, but not pre-numeric 0's.

Arla Nov 5th, 2007 12:08 PM

Re: String formatting
 
Knew I was being thick...

:

String.Format("{0:D8}", i)

This did it.


All times are GMT -5. The time now is 3:34 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC