NSLog中使用的格式符

Posted by Elton's Blog on November 13, 2009

NSLog在输出的时候,可以使用很多C中的格式符号,与print一样。 具体含义如下

** **Format specifiers supported by the \u000a```NSString\u000a``` formatting methods and CFString formatting functions
Specifier Description
\u000a```%@\u000a``` Objective-C object, printed as the string returned by \u000a```descriptionWithLocale:\u000a``` if available, or \u000a```description\u000a``` otherwise. Also works with \u000a```CFTypeRef\u000a``` objects, returning the result of the \u000a```CFCopyDescription\u000a``` function.
\u000a```%%\u000a``` \u000a```'%'\u000a``` character
\u000a```%d\u000a```, \u000a```%D\u000a```, \u000a```%i\u000a``` Signed 32-bit integer (\u000a```int\u000a```)
\u000a```%u\u000a```, \u000a```%U\u000a``` Unsigned 32-bit integer (\u000a```unsigned int\u000a```)
\u000a```%hi\u000a``` Signed 16-bit integer (\u000a```short\u000a```)
\u000a```%hu\u000a``` Unsigned 16-bit integer (\u000a```unsigned short\u000a```)
\u000a```%qi\u000a``` Signed 64-bit integer (\u000a```long long\u000a```)
\u000a```%qu\u000a``` Unsigned 64-bit integer (\u000a```unsigned long long\u000a```)
\u000a```%x\u000a``` Unsigned 32-bit integer (\u000a```unsigned int\u000a```), printed in hexadecimal using the digits 0–9 and lowercase a–f
\u000a```%X\u000a``` Unsigned 32-bit integer (\u000a```unsigned int\u000a```), printed in hexadecimal using the digits 0–9 and uppercase A–F
\u000a```%qx\u000a``` Unsigned 64-bit integer (\u000a```unsigned long long\u000a```), printed in hexadecimal using the digits 0–9 and lowercase a–f
\u000a```%qX\u000a``` Unsigned 64-bit integer (\u000a```unsigned long long\u000a```), printed in hexadecimal using the digits 0–9 and uppercase A–F
\u000a```%o\u000a```, \u000a```%O\u000a``` Unsigned 32-bit integer (\u000a```unsigned int\u000a```), printed in octal
\u000a```%f\u000a``` 64-bit floating-point number (\u000a```double\u000a```)
\u000a```%e\u000a``` 64-bit floating-point number (\u000a```double\u000a```), printed in scientific notation using a lowercase e to introduce the exponent
\u000a```%E\u000a``` 64-bit floating-point number (\u000a```double\u000a```), printed in scientific notation using an uppercase E to introduce the exponent
\u000a```%g\u000a``` 64-bit floating-point number (\u000a```double\u000a```), printed in the style of \u000a```%e\u000a``` if the exponent is less than –4 or greater than or equal to the precision, in the style of \u000a```%f\u000a``` otherwise
\u000a```%G\u000a``` 64-bit floating-point number (\u000a```double\u000a```), printed in the style of \u000a```%E\u000a``` if the exponent is less than –4 or greater than or equal to the precision, in the style of \u000a```%f\u000a``` otherwise
\u000a```%c\u000a``` 8-bit unsigned character (\u000a```unsigned char\u000a```), printed by \u000a```NSLog()\u000a``` as an ASCII character, or, if not an ASCII character, in the octal format \u000a```\ddd\u000a``` or the Unicode hexadecimal format \u000a```\udddd\u000a```, where \u000a```d\u000a``` is a digit
\u000a```%C\u000a``` 16-bit Unicode character (\u000a```unichar\u000a```), printed by \u000a```NSLog()\u000a``` as an ASCII character, or, if not an ASCII character, in the octal format \u000a```\ddd\u000a``` or the Unicode hexadecimal format \u000a```\udddd\u000a```, where \u000a```d\u000a``` is a digit
\u000a```%s\u000a``` Null-terminated array of 8-bit unsigned characters. \u000a```%s\u000a``` interprets its input in the system encoding rather than, for example, UTF-8.
\u000a```%S\u000a``` Null-terminated array of 16-bit Unicode characters
\u000a```%p\u000a``` Void pointer (\u000a```void *\u000a```), printed in hexadecimal with the digits 0–9 and lowercase a–f, with a leading \u000a```0x\u000a```
\u000a```%L\u000a``` Length modifier specifying that a following \u000a```a\u000a```, \u000a```A\u000a```, \u000a```e\u000a```, \u000a```E\u000a```, \u000a```f\u000a```, \u000a```F\u000a```, \u000a```g\u000a```, or \u000a```G\u000a``` conversion specifier applies to a \u000a```long double\u000a``` argument
\u000a```%a\u000a``` 64-bit floating-point number (\u000a```double\u000a```), printed in scientific notation with a leading \u000a```0x\u000a``` and one hexadecimal digit before the decimal point using a lowercase \u000a```p\u000a``` to introduce the exponent
\u000a```%A\u000a``` 64-bit floating-point number (\u000a```double\u000a```), printed in scientific notation with a leading \u000a```0X\u000a``` and one hexadecimal digit before the decimal point using a uppercase \u000a```P\u000a``` to introduce the exponent
\u000a```%F\u000a``` 64-bit floating-point number (\u000a```double\u000a```), printed in decimal notation
\u000a```%z\u000a``` Length modifier specifying that a following \u000a```d\u000a```, \u000a```i\u000a```, \u000a```o\u000a```, \u000a```u\u000a```, \u000a```x\u000a```, or \u000a```X\u000a``` conversion specifier applies to a \u000a```size_t\u000a``` or the corresponding signed integer type argument
\u000a```%t\u000a``` Length modifier specifying that a following \u000a```d\u000a```, \u000a```i\u000a```, \u000a```o\u000a```, \u000a```u\u000a```, \u000a```x\u000a```, or \u000a```X\u000a``` conversion specifier applies to a \u000a```ptrdiff_t\u000a``` or the corresponding unsigned integer type argument
\u000a```%j\u000a``` Length modifier specifying that a following \u000a```d\u000a```, \u000a```i\u000a```, \u000a```o\u000a```, \u000a```u\u000a```, \u000a```x\u000a```, or \u000a```X\u000a``` conversion specifier applies to a \u000a```intmax_t\u000a``` or \u000a```uintmax_t\u000a``` argument