2012-07-01 94 views
-1

我試圖編寫一個動態的URL,除了這樣做還有更簡單的方法來追加字符串嗎?這似乎效率低下。有沒有更簡單的方法將文本附加到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]; 

回答

2

可能:

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

謝謝,工程:) – sonicbabbler

相關問題