2010-11-29 70 views
0

我需要格式化像這樣的字符串:stringWithFormat中的字符串的格式化修飾符?

-(void)updateResult:(NSString*)name withAmount:(int)amount 
{ 
    NSString* result = [NSString stringWithFormat:@"%[email protected] with %8i €",name,amount]; 
    ... 
} 

的int格式的作品,但是字符串格式不對。我需要一個字符串,它使用15個字符。如果字符串較短,例如10個字符,剩下的5個字符應該用空格替換。

你能幫助請

問候camelord

回答

1

你可以使用%s其不接受長調節劑。

NSString* result = [NSString stringWithFormat:@"%15s with %8i €", 
               [name UTF8String], amount]; 
+0

啊,沒問題。謝謝! – camelord 2010-11-29 10:12:18