stringWithFormat和NSArray

时间:2012-02-17 15:24:11

标签: objective-c

我有一个带有对象的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做到这一点?

感谢

2 个答案:

答案 0 :(得分:6)

使用NSArray的{​​{1}}。

componentsJoinedByString:

答案 1 :(得分:2)

NSString *string = [NSString stringWithFormat:@"Dinner: %@",[array componentsJoinedByString:@","]];