如何在Objective-C中使用stringWithFormat方法追加字符串变量

时间:2010-06-16 12:38:59

标签: objective-c append stringwithformat

我想使用stringWithFormat将字符串附加到单个varilable中。我在使用stringByAppendingString时知道它。请帮我使用stringWithFormat为下面的代码添加。

NSString* curl = @"https://invoices?ticket=";
curl = [curl stringByAppendingString:self.ticket];
curl = [curl stringByAppendingString:@"&apikey=bfc9c6ddeea9d75345cd"];
curl = [curl stringByReplacingOccurrencesOfString:@"\n" withString:@""];

谢谢你, Madan Mohan。

1 个答案:

答案 0 :(得分:14)

您可以使用curl方法构建-stringWithFormat:字符串:

NSString *apiKey = @"bfc9c6ddeea9d75345cd";
NSString* curl = [NSString stringWithFormat:@"https://invoices?ticket=%@&apikey=%@", self.ticket, apiKey];