Objective C 字串補0

在連續檔案時常常需要用上,例如連續圖片的動畫,用這方法就非常的重要,例如需要一串png圖檔「a0001.png」~「a0100.png」,這時候就相當重要好用

就已上面這例子在Objective C當中產出這100個檔名來
for(int i = 1; i <= 100; i++){ [NSString stringWithFormat:@"%04d", i]; }


格式「%nd」 n:需要補滿至幾位數
sample %2d
1
2
3
...
10
11
12

格式「%0nd」0:用0補滿至n位數
sample %02d
01
02
03
...
10
11
12

沒有留言:

張貼留言