有没有更简单的方法将文本附加到NSString?

时间:2012-07-01 16:42:30

标签: objective-c nsstring

我正在尝试撰写动态网址,除了这样做之外,还有更简单的方法来追加字符串吗?这似乎效率低下。

NSString *folder1 = @"sonic";
NSString *folder2 = @"usr";
NSString *url = @"http://www.mydomain.com";

url = [url stringByAppendingFormat:@"/"];
url = [url stringByAppendingFormat:folder2];
url = [url stringByAppendingFormat:@"/"];
url = [url stringByAppendingFormat:folder1];

1 个答案:

答案 0 :(得分:2)

可能:

NSString *url = [NSString stringWithFormat:@"http://www.mydomain.com/%@/%@", folder2, folder1];