Objective c 使用stringByAppendingString连接时插入字符
有没有一种方法可以连接两个字符串并插入一个字符。我有:Objective c 使用stringByAppendingString连接时插入字符,objective-c,concatenation,code-injection,Objective C,Concatenation,Code Injection,有没有一种方法可以连接两个字符串并插入一个字符。我有: NSString *firstString = @"http://www.stackoverflow.com"; NSString *secondString = @"supercooloptions"; NSString *result = [firstString stringByAppendingString: secondString]; NSLog(@"the final string with "/" injection = %
NSString *firstString = @"http://www.stackoverflow.com";
NSString *secondString = @"supercooloptions";
NSString *result = [firstString stringByAppendingString: secondString];
NSLog(@"the final string with "/" injection = %@", result);
我希望最后一个字符串带有“/”injected=www.stackoverflow.com/supercoloptions您可以使用不同的方法-例如,
stringWithFormat
:
NSString *result = [NSString stringWithFormat:@"%@/%@", firstString, secondString];
您可以使用不同的方法,例如,
stringWithFormat
:
NSString *result = [NSString stringWithFormat:@"%@/%@", firstString, secondString];
对于此特定情况,请使用
stringByAppendingPathComponent:
NSString *result = [firstString stringByAppendingPathComponent:secondString];
对于此特定情况,请使用
stringByAppendingPathComponent:
NSString *result = [firstString stringByAppendingPathComponent:secondString];
尝试此NSString*结果=[firstString stringByAppendingFormat:@/%@],secondString];在我的例子中,Wain answer效果最好,在一般情况下,对于一般的字符注射目的,dasblinkenlight answer效果最好。谢谢大家的回答。警告:stringByAppendingPathComponent方法在->http://try this NSString*result=[firstString stringByAppendingFormat:@/%@],secondString]中去掉一个“/”;在我的例子中,Wain answer效果最好,在一般情况下,对于一般的字符注射目的,dasblinkenlight answer效果最好。谢谢大家的回答。警告:stringByAppendingPathComponent方法在->http://