在Objective-C字符串格式中添加零 [英] adding zeros in objective-c string formats
本文介绍了在Objective-C字符串格式中添加零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如,我想:
@数字是%d,5 //我希望这样输出'数字是05'
@数字是%d,10 //我要这个输出'数字是10'
我知道如何在Java中做到这一点,但我似乎无法在objective-c中找到相同的函数。
如果在Java中使用 System.out.printf()
/ code>,那么它在Objective-C(和C中就是这个意思)中是相同的格式语法:
$ p $ NSLog(@号码是%02d,5);
NSLog(@号码是%02d,10);
Quick question: I am trying to fill in empty spaces with a specific number of zeroes in an NSString stringWithFormat formatting string.
For example, I want:
@"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'
I know how to do this in Java, but I cant seem to find the same function in objective-c.
Any help would be great.
解决方案
If in Java you use System.out.printf()
, then it's the same format syntax in Objective-C (and C, for that matter):
NSLog(@"The number is %02d", 5);
NSLog(@"The number is %02d", 10);
这篇关于在Objective-C字符串格式中添加零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文