我有一个带有对象的NSArray:
NSArray *array = [NSArray arrayWithObjects:@"Saturday",@"Sunday",@"Monday",@"tuesday",@"Wednesday",@"thursday",nil];
有时候会这样:
array = [NSArray arrayWithObjects:@"Tuesday",@"Monday",nil];
我想要一个这样的字符串:
dinner : sunday, monday,tusday, wednesday, thurs...
或
dinner : tuesday, monday.
我怎么能用stringWithFormat做到这一点?
感谢
答案 0 :(得分:6)
使用NSArray
的{{1}}。
componentsJoinedByString:
答案 1 :(得分:2)
NSString *string = [NSString stringWithFormat:@"Dinner: %@",[array componentsJoinedByString:@","]];