1

有没有办法连接两个字符串并注入一个字符。我有 :

NSString *firstString = @"http://www.stackoverflow.com";
NSString *secondString = @"supercooloptions";
NSString *result = [firstString stringByAppendingString: secondString];
NSLog(@"the final string with "/" injection = %@", result);

我想要带有“/”的最后一个字符串注入 = www.stackoverflow.com/supercooloptions

4

2 回答 2

6

您可以使用不同的方法 - 例如,stringWithFormat

NSString *result = [NSString stringWithFormat:@"%@/%@", firstString, secondString];
于 2013-11-15T11:22:57.627 回答
5

对于这种特定情况,请使用stringByAppendingPathComponent:

NSString *result = [firstString stringByAppendingPathComponent:secondString];
于 2013-11-15T11:23:05.870 回答