文書の過去の版を表示しています。
NSStringで使える書式指定子
Mac OS X v10.6の「String Format Specifiers」より抜粋。
| 指定子 | 解説 |
|---|---|
| %@ | Objective-Cオブジェクト。利用可能なら<ilcode>descriptionWithLocale:</ilcode>ないし<ilcode>description</ilcode>が返す文字列を表示する。同様に<ilcode>CFTypeRef</ilcode>オブジェクトも対象で、<ilcode>CFCopyDescription</ilcode>の結果を返す。 |
| %% | '%'文字 |
| %d, %D, %i | 符号あり32ビット整数(int) |
| %u, %U | 符号なし32ビット整数(unsigned int) |
| %hi | 符号あり16ビット整数(short) |
| %hu | 符号なし16ビット整数(unsigned short) |
| %qi | 符号あり64ビット整数(long long) |
| %qu | 符号なし64ビット整数(unsigned long long) |
| %x | 符号なし32ビット整数(unsigned int)を16進表記。小文字のa〜fを用いる。 |
| %X | 符号なし32ビット整数(unsigned int)を16進表記。大文字のA〜Fを用いる。 |
| %qx | 符号なし64ビット整数(unsigned int)を16進表記。小文字のa〜fを用いる。 |
| %qX | 符号なし64ビット整数(unsigned int)を16進表記。大文字のA〜Fを用いる。 |
| %o, %O | 符号なし32ビット整数(unsigned int)を8進表記。 |
| %f | 64ビット浮動小数点値(double) |
| %e | 64ビット浮動小数点値(double)を指数表記。指数文字は小文字のeを用いる。 |
| %E | 64ビット浮動小数点値(double)を指数表記。指数文字は大文字のEを用いる。 |
| %g | 64-bit floating-point number (double), printed in the style of %e if the exponent is less than –4 or greater than or equal to the precision, in the style of %f otherwise |
| %G | 64-bit floating-point number (double), printed in the style of %E if the exponent is less than –4 or greater than or equal to the precision, in the style of %f otherwise |
| %c | 8ビット符号なし文字(unsigned char)。<ilcode>NSLog()</ilcode>ではASCIIキャラクターを表示し、非ASCIIキャラクターの場合は\\dddの8進表記で、Unicodeは\\uddddの16進表記で表示する(ここでdは桁を表す)。 |
| %C | 16ビットUnicode文字(unichar)。<ilcode>NSLog()</ilcode>ではASCIIキャラクターを表示し、非ASCIIキャラクターの場合は\\dddの8進表記で、Unicodeは\\uddddの16進表記で表示する(ここでdは桁を表す)。 |
| %s | NULL終端の8ビット符号なし文字配列。%s interprets its input in the system encoding rather than, for example, UTF-8. |
| %S | NULL終端の16ビットUnicode文字配列。 |
| %p | voidポインタ(void *)。0xに続く16進表記。小文字のa〜fを用いる。 |
| %L | 長さ修飾子。a, A, e, E, f, F, g, Gを修飾すると、long doubleの引数を受ける指定子へ変化する。 |
| %a | 64-bit floating-point number (double), printed in scientific notation with a leading 0x and one hexadecimal digit before the decimal point using a lowercase p to introduce the exponent |
| %A | 64-bit floating-point number (double), printed in scientific notation with a leading 0X and one hexadecimal digit before the decimal point using a uppercase P to introduce the exponent |
| %F | 64-bit floating-point number (double), printed in decimal notation |
| %z | Length modifier specifying that a following d, i, o, u, x, or X conversion specifier applies to a size_t or the corresponding signed integer type argument |
| %t | Length modifier specifying that a following d, i, o, u, x, or X conversion specifier applies to a ptrdiff_t or the corresponding unsigned integer type argument |
| %j | Length modifier specifying that a following d, i, o, u, x, or X conversion specifier applies to a intmax_t or uintmax_t argument |