1

We need to format a string, but for some localisations we won't output all parameters. But it seems that it doesn't work to output less parameters than passed:

NSString *string = [NSString stringWithFormat: @"%2$@", @"<1111>", @"<22222>"];
NSLog(@"String = %@", string);

Outputs

String = <1111>

although i output the second parameter. Is this a bug or a feature?

wutzebaer
  • 13,422
  • 18
  • 88
  • 157
  • It is unclear what you are doing and trying to achieve in your question. Please clarify it. – rptwsthi Jan 07 '16 at 14:40
  • you have to use both parameters, you can't just use the second – Wain Jan 07 '16 at 14:42
  • according to the industrial standard: _"When numbered argument specifications are used, specifying the Nth argument __requires that all the leading arguments__, from the first to the (N-1)th, __are specified in the format string__."_ ([source](http://pubs.opengroup.org/onlinepubs/009695399/functions/printf.html)) – holex Jan 07 '16 at 14:42

1 Answers1

3

according to the related industrial standard, IEEE specification:

When numbered argument specifications are used, specifying the Nth argument requires that all the leading arguments, from the first to the (N-1)th, are specified in the format string.


which means in other words, you must use the first %1$@ parameter in your string formatter somewhere before you address to use the second one – so, it is not a bug at all.

holex
  • 23,814
  • 7
  • 61
  • 76