4

I have the following line of code:

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

The 80.1 is a float that is being inserted into the localized string. This works fine. However I want a % symbol in the localized string. I have tried using %%, but it does not output the % symbol - instead it outputs a space, the numbers 5302 and also removes part of the string that precedes the %% characters.

How can I add a % symbol to a string returned by NSLocalizedString?

Darren
  • 10,091
  • 18
  • 65
  • 108

2 Answers2

3

I think the problem is not with the NSLocalizedString, but with NSLog's interpretation of % symbol. If you pass a format string to NSLog, and put the string that you would like to show as an object parameter, the percentage sign % should survive:

NSLog(@"%@", [NSString stringWithFormat:NSLocalizedString(@"KEY", nil),80.1]);
Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523
0

Alternatively: The first argument for NSLog is a format string. You've got a format string, so you should pass it to NSLog:

NSLog (NSLocalizedString (@"KEY", nil), 80.1);
gnasher729
  • 51,477
  • 5
  • 75
  • 98