开发者

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];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜