Possible Duplicate:
How to add percent sign to NSString可能重复:如何将百分号添加到NSString
Trying to create some string output using the % symbol with no luck:
尝试使用%符号创建一些字符串输出而没有运气:
[NSString stringWithFormat:@"%@% off entire order.",self.discountPercentage.text]
Example output would hopefully be something like: 25% off entire order.
希望示例输出如下:整个订单可享受25%的折扣。
Instead I get some crazy output: 25377777777776ff entire order.
相反,我得到一些疯狂的输出:25377777777776ff整个订单。
Is there an escape character I need to use before the %?
在%之前我需要使用转义字符吗?
2 个解决方案
#1
2
The code for percent sign in NSString format is %%.This is also true for NSLog() and printf() formats.
NSString格式的百分号代码是%%。对于NSLog()和printf()格式也是如此。
#2
5
Use %%
to represent the % characters. (See String Programming Guide: String Format Specifiers)
使用%%表示%字符。 (参见字符串编程指南:字符串格式说明符)
#1
2
The code for percent sign in NSString format is %%.This is also true for NSLog() and printf() formats.
NSString格式的百分号代码是%%。对于NSLog()和printf()格式也是如此。
#2
5
Use %%
to represent the % characters. (See String Programming Guide: String Format Specifiers)
使用%%表示%字符。 (参见字符串编程指南:字符串格式说明符)