2013-02-28 1 views
1

Je veux personnaliser une méthode avec entrée de chaîne formées et retour (const char *), mais le problème est comme ci-dessous ... Quelqu'un peut-il me dire comment le résoudre? Merci. I want to customize a method with formated string input and (const char *) return,but the problem is like below... Can anyone tell me how to resolve it? Thanks.Comment personnaliser une méthode comme 'stringWithFormat'?

+0

Souhaitez-vous transmettre un nombre variable d'arguments? –

+0

Oui. Je veux personnaliser une méthode comme [NSString stringWithFormat: <# (NSString *), ... #>]; – stream

Répondre

5
-(const char *)stringWithFormat:(NSString *)format, ... 
{ 
    va_list args; 
    va_start(args, format); 
    NSString *lString = [[NSString alloc] initWithFormat:format arguments:args]; 
    [lString autorelease]; 
    va_end(args); 
    return [lString cStringUsingEncoding:NSUTF8StringEncoding]; 

} 
+0

Parfait, merci! – stream

+1

@stream: Incroyable vous avez accepté, mais din't upvoted !!! Toujours upvote si vous aimez une réponse. cela stimule la personne qui donne le temps de répondre. Et en lisant vous apprenez quelque chose. :) –

+0

+1 de mon côté à Parag. –

Questions connexes