NSString stringWithFormat 少参数
NSString stringWithFormat less parameters
我们需要格式化字符串,但对于某些本地化版本,我们不会输出所有参数。但是输出的参数比passed少好像不行:
NSString *string = [NSString stringWithFormat: @"%2$@", @"<1111>", @"<22222>"];
NSLog(@"String = %@", string);
产出
String = <1111>
虽然我输出了第二个参数。
这是错误还是功能?
根据相关行业标准,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.
换句话说,您必须在字符串格式化程序的某个地方使用第一个 %1$@
参数,然后才能使用第二个参数 - 所以,这根本不是错误。
我们需要格式化字符串,但对于某些本地化版本,我们不会输出所有参数。但是输出的参数比passed少好像不行:
NSString *string = [NSString stringWithFormat: @"%2$@", @"<1111>", @"<22222>"];
NSLog(@"String = %@", string);
产出
String = <1111>
虽然我输出了第二个参数。 这是错误还是功能?
根据相关行业标准,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.
换句话说,您必须在字符串格式化程序的某个地方使用第一个 %1$@
参数,然后才能使用第二个参数 - 所以,这根本不是错误。