I have a starting number to work from which is 0000 and increment it by one, i have that done, but the result is 1,2,3 instead of 0001,0002,0003 etc. How can I achieve this?
I use this string:
stringa = [NSString stringWithFormat:@"Score: %d",score];
Thank you.
stringa = [NSString stringWithFormat:@"Score: %04d",score];
should do what you want.
"4" is the (minimum) field width, and the "0" is for padding with zeroes instead of spaces.
stringWithFormat
understands (almost) all the "printf" formats
(which are described in detail here: http://pubs.opengroup.org/onlinepubs/009695399/functions/printf.html ).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With