I am trying to generate a numerical string by padding the number with zeroes to the left.
0 would become 00000 1 would become 00001 10 would become 00010
I want to create five character NSString
by padding the number with zeroes.
I read this Create NSString by repeating another string a given number of times but the output is an NSMutableString
.
How can I implement this algorithm with the output as an NSString
?
Best regards.
You can accomplish this by calling
[NSString stringWithFormat:@"%05d", [theNumber intValue]];
where theNumber
is the NSString
containing the number you want to format.
For further reading, you may want to look at Apple's string formatting guide or the Wikipedia entry for printf.
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