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 20000943 for examples of how to use this method, and TP40004265 for a list of format specifiers. This value must not be
nil.Raises an
NSInvalidArgumentExceptionifformatisnil.
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
Pass a comma-separated list of variadic arguments to substitute into format.
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 description(withLocale:) 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
stringinit()init(bytes:length:encoding:)init(bytesNoCopy:length:encoding:freeWhenDone:)init(characters:length:)init(charactersNoCopy:length:freeWhenDone:)init(string:)initWithFormat:init(format:arguments:)initWithFormat:locale:init(format:locale:arguments:)init(data:encoding:)stringWithFormat:localizedUserNotificationString(forKey:arguments:)stringWithCharacters:length: