如何自定义像'stringWithFormat'这样的方法?

时间:2013-02-28 05:49:23

标签: objective-c format cstring stringwithformat

我想自定义一个带有格式化字符串输入和(const char *)返回的方法,但问题如下:有谁能告诉我如何解决它?谢谢。 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.

1 个答案:

答案 0 :(得分:7)

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

}