Jun 16, 2014

Format NSString to left pad zeroes in Objective C

Posted Jun 16, 2014
01, 02, 03, 04, 05..
int num = 1;
[NSString stringWithFormat:@"%02d", num];

001, 002, 003, 004, 005..
[NSString stringWithFormat:@"%03d", num];

0001, 0002, 0003, 0004, 0005..
[NSString stringWithFormat:@"%04d", num];

You get the pattern? Good!


No comments:

Post a Comment