2013-07-19 79 views
-2

我想追加兩個NSMutablestring,但我想讓它們之間的逗號分隔。現在,我使用的代碼是這樣的:用逗號分隔NSMutablestring

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

結果是:這是一個stringThis是一個String

我試着用:

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

但仍沒有運氣。

請幫忙,問候。

+4

是什麼'astring'包含哪些內容?你會得到什麼結果?你期望什麼結果? –

+0

這應該工作,你得到什麼輸出和你的期望。 – Amit

+1

這不是一個Xcode的問題... – 2013-07-19 09:33:48

回答

0

我用這個和它的工作對我罰款:

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

O/P:string : ,I am appending this string

0
teststring = [[NSMutableString alloc]init]; 
[teststring appendString:@","]; 
    [teststring appendString:astring]; 
0

試試這個

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

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

NSLog(@"%@",teststring); 
0

試試這個

NSString *string = @"Hello World"; 

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

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

如果你想看到這個字符串

NSLog(@"%@",secondstring);