NSString stringWithFormat less parameters [duplicate]

随声附和 提交于 2019-12-23 01:42:08

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/34657641/nsstring-stringwithformat-less-parameters

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!