The form:% 2 $ @,% 1 $ @,% 2 $ d,% 1 $ d placeholder

%1$@
%2$@
%1$d
%2$d

OC section of code that is similar in other languages

NSString *total = @"10";
NSString *sub = @"3";

NSString *enStr = @"%@ of %@";
NSString *chStr = @"%2$@ 个中的 %1$@ 个";
        
NSString *egLishString = [NSString stringWithFormat:enStr,sub,total];
NSLog(@"%@", egLishString);  // 3 of 10
        
NSString *chLishString = [NSString stringWithFormat:chStr,sub,total];
NSLog(@"%@", chLishString);  //10 个中的 3 个
  1. Digital placeholder indicates that the filling position of several parameters
   [NSString stringWithFormat:@"%2$@ 个中的 %1$@ 个", sub, total]
  1. Placeholder character to indicate that the position of the filling parameters Type
    @: Object Type, D: integer, S: String, ...
Published 34 original articles · won praise 20 · views 20000 +

Guess you like

Origin blog.csdn.net/ZhangWangYang/article/details/104668469