-2

我正在尝试附加两个 NSMutablestring,但我想在它们之间使用逗号分隔。现在我使用的代码是这样的:

NSString *astring = @"This is a string";
teststring = [[NSMutableString alloc]init];
[teststring appendString:astring];
NSLog(@"%@",teststring);

结果是:这是一个字符串这是一个字符串

我尝试:

[teststring appendFormat:@",%@",astring];

但仍然没有运气。

请帮忙,问候。

4

4 回答 4

0
  teststring = [[NSMutableString alloc]init];
 [teststring appendString:@","];
  [teststring appendString:astring];
于 2013-07-19T08:57:01.363 回答
0

尝试这个

NSString *astring = @"This is a string";
teststring = [[NSMutableString alloc]init];

[teststring appendString:astring];
[teststring appendString:@","];
[teststring appendString:astring];

NSLog(@"%@",teststring);
于 2013-07-19T09:12:03.610 回答
0

尝试这个

NSString *string = @"Hello World";

NSMutableString * secondstring =[[NSMutableString alloc]init];

[secondstring appendString:string] 
[secondstring appendString:@","];
[secondstring appendString:string];

如果你想看到这个字符串

NSLog(@"%@",secondstring);
于 2013-07-19T09:17:54.500 回答
0

我使用了它,它对我来说工作正常:

NSMutableString *teststring = [[NSMutableString alloc]init];
NSMutableString *astring = [[NSMutableString alloc]init];
[astring appendString:@"I am appending this string"];
[teststring appendFormat:@",%@",astring];
NSLog(@"string : %@",teststring);

开/关: string : ,I am appending this string

于 2013-07-19T08:53:17.053 回答