Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 使用stringByAppendingString连接时插入字符_Objective C_Concatenation_Code Injection - Fatal编程技术网

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://