简单问题:我试图在 NSString stringWithFormat 格式化字符串中用特定数量的零填充空格。
例如,我想要:
@"The number is %d", 5 // I want this to output 'the number is 05'
@"the number is %d", 10 // I want this to output 'the number is 10'
我知道如何在 Java 中执行此操作,但我似乎无法在 Objective-C 中找到相同的函数。
任何帮助都会很棒。
最佳答案
如果在 Java 中使用 System.out.printf()
,那么它与 Objective-C(以及 C,就此而言)中的格式语法相同:
NSLog(@"The number is %02d", 5);
NSLog(@"The number is %02d", 10);
关于iphone - 在 Objective-C 字符串格式中添加零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4697510/