有没有办法连接两个字符串并注入一个字符。我有:
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
答案 0 :(得分:6)
您可以使用其他方法 - 例如stringWithFormat
:
NSString *result = [NSString stringWithFormat:@"%@/%@", firstString, secondString];
答案 1 :(得分:5)
对于此特定情况,请使用stringByAppendingPathComponent:
NSString *result = [firstString stringByAppendingPathComponent:secondString];