i have a nsmutablearray which have 5 objects.
for example if it contain objects like apple, cat , ball, dog ,ant, i want them to append with comma separated that is like apple, cat , ball, dog ,ant. please help me with this.
edit
publishingpost //nsmutable array contains all these object
-(ibaction)post
{
nsstring *str;
nsstring *str2 =@",";
for(int i = 0; i< [publishingpost count]; i++){
nsstring *str = [publishingpost objectAtIndex:i];
//append both str1, str2 to generate comma separated objects
}
use - (NSString *)componentsJoinedByString:(NSString *)separator
instead:
- (IBAction)post {
NSString * str = [publishingpost componentsJoinedByString:@", "];
}
Take a look at stringByAppendingString:
or stringByAppendingFormat
from here . It should be easy enough to do if you already have the Strings.
Declare an NSString object before the for loop (or use str
) and append to that while going through the loop. And you're not supposed to declare str
twice in your code. Might want to rename one of them.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.