Question

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?

Was it helpful?

Solution

Use the string.Format command.

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

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

OTHER TIPS

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

but there is some useful documentation here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top