Skip to content

String Format Specifiers

binism edited this page Mar 13, 2016 · 7 revisions

String Format Specifiers

字符串格式说明符

本文总结了字符串格式化函数、方法所支持的格式化标识符。

格式化标识符

NSString字符格式化方法和CFSting字符格式化函数所支持的格式化标识符遵循 IEEE printf specification;这些标识符的使用总结在了Table 1。注意,你也可以使用像“n$"这样的位置标识符(如:%1$ %2$)。获取更多细节,参见 IEEE printf specification。同样,你也可以把这些格式化标识符用在NSLog函数中。

Table 1 NSString字符格式化方法和CFSting字符格式化函数所支持的格式化标识符

Specifier Description
%@ Objective-C object, printed as the string returned by descriptionWithLocale: if available, or description otherwise. Also works with CFTypeRef objects, returning the result of the CFCopyDescription function.
%% '%' character.
%d,%D Signed 32-bit integer (int).

Clone this wiki locally