The% character in NSLocalizedString

I have the following line of code:

NSLog([NSString stringWithFormat:NSLocalizedString(@"KEY", nil),80.1]); 

80.1 is a float that is inserted into a localized string. It works great. However, I want the% character in a localized string. I tried using %%, but it does not output the% character - instead, it displays the space, the numbers 5302, and also removes the part of the line that precedes the %% characters.

How to add the% character to the string returned by NSLocalizedString?

+4
source share
2 answers

I think that the problem is not with NSLocalizedString , but with the interpretation of the NSLog character % . If you pass the format string to NSLog and put the string you want to show as an object parameter, the% percent sign should be preserved:

 NSLog(@"%@", [NSString stringWithFormat:NSLocalizedString(@"KEY", nil),80.1]); 
+3
source

Alternatively: the first argument to NSLog is the format string. You have a format string, so you must pass it to NSLog:

 NSLog (NSLocalizedString (@"KEY", nil), 80.1); 
0
source

All Articles