Formatting modifiers for a string inside stringWithFormat?
i need a String formated like this:
-(void)updateResult:(NSString*)name withAmount:(int)amount
{
NSString* result = [NSString stringWithFormat:@"%15@ with %8i €",name,amount];
...
}
The int开发者_如何学Python format works, but the string format doesn't. I need a String, that uses 15 characters. If the string is shorter, e.g. 10 character, the remaining 5 ones should be replaced with an empty space.
can you help please
regards camelord
You could use %s
which does accept the length modifier.
NSString* result = [NSString stringWithFormat:@"%15s with %8i €",
[name UTF8String], amount];
精彩评论