Reputation: 6451
I am trying to concatenate the contents of an NSMutableArray
using
NSString* result = @"";
for(NSString* test in self.selectedOnes) {
NSLog(test) ;
[result stringByAppendingString:test];
[result stringByAppendingString:@","];
}
but result
remains @""
, I am sure that the selectedOnes
contains data because it writes to the log.
Any suggestions?
Upvotes: 1
Views: 115
Reputation: 51374
You can use the componentsJoinedByString
method which "Constructs and returns an NSString object that is the result of interposing a given separator between the elements of the array",
NSString *result = [self.SelectedOnes componentsJoinedByString:@","];
Upvotes: 4
Reputation: 10755
Try this way
result = test;
result = [result stringByAppendingString:@","];
Upvotes: 0
Reputation: 3321
stringByAppendingString:
returns a new String.
This should work.
NSString* result = @"";
for(NSString* test in self.SelectedOnes )
{
NSLog( test ) ;
result = [result stringByAppendingString:test];
result = [result stringByAppendingString:@","];
}
Upvotes: 2
Reputation: 90117
stringByAppendingString:
returns a new string
Use it like this:
NSString* result = @"";
for(NSString* test in self.SelectedOnes )
{
NSLog( test ) ;
result = [result stringByAppendingString:test];
result = [result stringByAppendingString:@","];
}
Upvotes: 2