2010-11-29 5 views
0

i besoin d'une chaîne formated comme ceci:Modificateurs de formatage pour une chaîne à l'intérieur de stringWithFormat?

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

Le format int fonctionne, mais le format de la chaîne ne fonctionne pas. J'ai besoin d'une chaîne, qui utilise 15 caractères. Si la chaîne est plus courte, par ex. 10 caractères, les 5 restants doivent être remplacés par un espace vide.

peut vous aider à satisfaire

concernant camelord

Répondre

1

Vous pouvez utiliser %s qui n'accepte le modificateur de longueur.

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

ahh, ok cela a fonctionné. THX! – camelord

Questions connexes