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?
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?
Use the string.Format command.
output = String.Format("{0:0000}", intVariable);
More details: http://msdn.microsoft.com/en-us/library/fht0f5be.aspx
i think it was: intVal.ToString( "####" );
but there is some useful documentation here