Type Method

localizedStringWithFormat:

Returns a string created by using a given format string as a template into which the remaining argument values are substituted according to the current locale.

Declaration

+ (instancetype)localizedStringWithFormat:(NSString *)format, ...;

Parameters

format

A format string. See Formatting String Objects for examples of how to use this method, and String Format Specifiers for a list of format specifiers. This value must not be nil.

Raises an NSInvalidArgumentException if format is nil.

...

A comma-separated list of arguments to substitute into format.

Return Value

A string created by using format as a template into which the following argument values are substituted according to the formatting information in the current locale.

Discussion

This method is equivalent to using initWithFormat:locale: and passing the current locale as the locale argument.

As an example of formatting, this method replaces the decimal according to the locale in %f and %d substitutions, and calls descriptionWithLocale: instead of description where necessary.

This code excerpt creates a string from another string and a float:

NSString *myString = [NSString localizedStringWithFormat:@"%@:  %f\n", @"Cost", 1234.56];

The resulting string has the value “Cost: 1234.560000\n” if the locale is en_US, and “Cost: 1234,560000\n” if the locale is fr_FR.

See Formatting String Objects for more information.

See Also

Creating and Initializing Strings

string

Returns an empty string.

init

Returns an initialized NSString object that contains no characters.

initWithBytes:length:encoding:

Returns an initialized NSString object containing a given number of bytes from a given buffer of bytes interpreted in a given encoding.

initWithBytesNoCopy:length:encoding:freeWhenDone:

Returns an initialized NSString object that contains a given number of bytes from a given buffer of bytes interpreted in a given encoding, and optionally frees the buffer.

initWithCharacters:length:

Returns an initialized NSString object that contains a given number of characters from a given C array of UTF-16 code units.

initWithCharactersNoCopy:length:freeWhenDone:

Returns an initialized NSString object that contains a given number of characters from a given C array of UTF-16 code units.

initWithString:

Returns an NSString object initialized by copying the characters from another given string.

initWithCString:encoding:

Returns an NSString object initialized using the characters in a given C array, interpreted according to a given encoding.

initWithUTF8String:

Returns an NSString object initialized by copying the characters from a given C array of UTF8-encoded bytes.

initWithFormat:

Returns an NSString object initialized by using a given format string as a template into which the remaining argument values are substituted.

initWithFormat:arguments:

Returns an NSString object initialized by using a given format string as a template into which the remaining argument values are substituted without any localization.

initWithFormat:locale:

Returns an NSString object initialized by using a given format string as a template into which the remaining argument values are substituted according to given locale.

initWithFormat:locale:arguments:

Returns an NSString object initialized by using a given format string as a template into which the remaining argument values are substituted according to given locale information. This method is meant to be called from within a variadic function, where the argument list will be available.

initWithData:encoding:

Returns an NSString object initialized by converting given data into UTF-16 code units using a given encoding.

stringWithFormat:

Returns a string created by using a given format string as a template into which the remaining argument values are substituted.

localizedUserNotificationStringForKey:arguments:

Returns a localized string intended for display in a notification alert.

stringWithCharacters:length:

Returns a string containing a given number of characters taken from a given C array of UTF-16 code units.

stringWithString:

Returns a string created by copying the characters from another given string.

stringWithCString:encoding:

Returns a string containing the bytes in a given C array, interpreted according to a given encoding.

stringWithUTF8String:

Returns a string created by copying the data from a given C array of UTF8-encoded bytes.

unichar

Type for UTF-16 code units.