Int号0000 cocos2d

Ste*_*ani 4 iphone objective-c string-formatting nsstring

我有一个起始编号工作从0000是由一个增加它,我有工作要做,但结果是1,2,3,而不是0001,0002,0003等我怎样才能做到这一点?

我用这个字符串:

stringa = [NSString stringWithFormat:@"Score: %d",score];
Run Code Online (Sandbox Code Playgroud)

谢谢.

Mar*_*n R 9

stringa = [NSString stringWithFormat:@"Score: %04d",score];
Run Code Online (Sandbox Code Playgroud)

应该做你想做的事.

"4"是(最小)字段宽度,"0"是用零填充而不是空格填充. stringWithFormat理解(几乎)所有"printf"格式(这里详细描述:http://pubs.opengroup.org/onlinepubs/009695399/functions/printf.html).