-1

我正在尝试编写一个动态 URL,除了以这种方式附加字符串之外,还有其他更简单的方法吗?这似乎效率低下。

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

1 回答 1

2

可能:

NSString *url = [NSString stringWithFormat:@"http://www.mydomain.com/%@/%@", folder2, folder1];
于 2012-07-01T17:00:29.193 回答