A format specifier such as `%15@` works in NSLog but not with NSString stringWithFormat
问题 I found something strange when trying to use width specifiers with %@ . They work fine in NSLog but not with NSString stringWithFormat: . Example: NSString *rightAligned = @"foo"; NSString *leftAligned = @"1"; NSLog(@"| %15@ | %-15@ |", rightAligned, leftAligned); And you get the expected output of: | foo | 1 | But replace the NSLog with stringWithFormat: : NSString *test = [NSString stringWithFormat:@"| %15@ | %-15@ |", rightAligned, leftAligned]; And the value of test is incorrectly: | foo