views:

506

answers:

2

I need to pad the output of an integer to a given length.

For example, with a length of 4 digits, the output of the integer 4 is "0004" instead of "4". How can I do this in C# 2.0?

+11  A: 

Use the string.Format command.

output = String.Format("{0:0000}", intVariable);

More details: http://msdn.microsoft.com/en-us/library/fht0f5be.aspx

Stephen Wrighton
+1  A: 

i think it was: intVal.ToString( "####" );

but there is some useful documentation here

Kris
This is also helpful for me. Thanks
leon ching