convert int into string with certain length of char

Posted by Tommy on Stack Overflow See other posts from Stack Overflow or by Tommy
Published on 2010-06-12T22:36:05Z Indexed on 2010/06/12 22:43 UTC
Read the original article Hit count: 188

Filed under:
|

If the title wasn't clear, ill try to explain it well here. I have a bunch of integers, ranging from 1 to 999, and i need to convert these into strings, but when i do that, i need them to be 3 characters long. so for instance, if i had:

int i1 = 45;

then when i turned that into a string, i'd need this: "045" or similarly, if i had an int of 8 then that would have to turn into "008", and if anything had 3 places, such as 143, then it would just be outputted as 143. is this easily possible?

Thanks for responses in advance. :)

© Stack Overflow or respective owner

Related posts about c#

Related posts about string-conversion