我在这里尝试了几个示例,希望对您有所帮助。
NSString *string1 = @"String1";
NSString *string2 = @"String2 String3";
NSMutableString *appendingString=[NSMutableString stringWithString: [string1 stringByAppendingString:string2]];
NSLog(@"String1:%@ String2:%@",string1,string2);
NSLog(@"StringwithAppend:%@",appendingString);
//------
NSString *url=@"www.abc.com";
NSMutableString * urlString = [NSMutableString stringWithString:url];
NSLog(@"URL String before append:%@",urlString);
NSString *kWord=@"key";
NSString *word=@"word";
[urlString appendString:[NSString stringWithFormat:@"?%@=%@",kWord,word]];
NSLog(@"URL String after append:%@",urlString);
控制台日志:
String1:String1 String2:String2 String3 StringwithAppend:String1String2 String3 URL 追加前的字符串:www.abc.com URL 追加后的字符串:www.abc.com?key=word