Objective-C String Format Specification

April 8, 2009 § Leave a comment

Format specifiers are most commonly used but they are not discussed in depth.

NSString formatting methods, CFString formatting functions and NSLog function support the format specifiers. It deliver similar results like printf specification.

%@ – string
%% – ‘%’ character
%d – signed 32-bit integer (int)
%D – signed 32-bit integer (int)
%i – signed 32-bit integer (int)
%u – unsigned 32-bit integer (unsigned int)
%U – unsigned 32-bit integer (unsigned int)
%f – 64-bit floating-point number (double)
%F – 64-bit floating-point number (double) printed in decimal notation
%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
%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
– %s Null-terminated array of 8-bit unsigned characters. %s interprets input in the system encoding UTF-8

You can use “n$” positional specification.

%1$@ %2$s

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

What’s this?

You are currently reading Objective-C String Format Specification at Web Builders.

meta

%d bloggers like this: