iphonesdk附加字符串问题
我有一个 nsmutablearray 有 5 个对象。
例如,如果它包含苹果、猫、球、狗、蚂蚁等对象,我希望它们附加以逗号分隔,例如苹果、猫、球、狗、蚂蚁。请帮我解决这个问题。
编辑
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
}
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
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
- (NSString *)componentsJoinedByString:(NSString *)separator
代替:use
- (NSString *)componentsJoinedByString:(NSString *)separator
instead:查看 此处。如果你已经有了弦,这应该很容易做到。
在 for 循环之前声明一个 NSString 对象(或使用
str
),并在循环过程中附加到该对象。并且您不应该在代码中声明str
两次。可能想重命名其中之一。Take a look at
stringByAppendingString:
orstringByAppendingFormat
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 declarestr
twice in your code. Might want to rename one of them.