I am sorry if this is an FAQ, but what is the difference between the two statements below? I have been looking on google and also on Apples documentation and I can't seem to find a salid开发者_开发问答 difference. My best guess is the localised one is optimised to be updated at runtime. Could anyone kindly clarify for me?
NSString *title1 = [NSString localizedStringWithFormat:@"%@, %@", @"1", @"2"];
.
NSString *title2 = [NSString stringWithFormat:@"%@, %@", @"1", @"2"];
much appreciated
gary
From NSString Class Reference:
This method is equivalent to using initWithFormat:locale: and passing [[NSUserDefaults standardUserDefaults] dictionaryRepresentation] 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.
NSString Class Reference
Read the discussion in the docs on the method. It details what it is for. Its purpose is to apply locale formatting, such as correct decimal separators (period versus comma in floating point numbers). Read Formatting String Objects for more details.
精彩评论