Hak*_*lee 1 concatenation objective-c code-injection
有没有办法连接两个字符串并注入一个字符.我有 :
NSString *firstString = @"http://www.stackoverflow.com";
NSString *secondString = @"supercooloptions";
NSString *result = [firstString stringByAppendingString: secondString];
NSLog(@"the final string with "/" injection = %@", result);
Run Code Online (Sandbox Code Playgroud)
我希望注入"/"的最终字符串= www.stackoverflow.com/supercooloptions
您可以使用其他方法 - 例如stringWithFormat:
NSString *result = [NSString stringWithFormat:@"%@/%@", firstString, secondString];
Run Code Online (Sandbox Code Playgroud)
对于这种特定情况,请使用 stringByAppendingPathComponent:
NSString *result = [firstString stringByAppendingPathComponent:secondString];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
120 次 |
| 最近记录: |