iphonesdk附加字符串问题

发布于 2024-12-13 05:16:13 字数 439 浏览 1 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

谢绝鈎搭 2024-12-20 05:16:13

使用 - (NSString *)componentsJoinedByString:(NSString *)separator 代替:

- (IBAction)post {
   NSString * str = [publishingpost componentsJoinedByString:@", "];
}

use - (NSString *)componentsJoinedByString:(NSString *)separator instead:

- (IBAction)post {
   NSString * str = [publishingpost componentsJoinedByString:@", "];
}
摘星┃星的人 2024-12-20 05:16:13

查看 此处。如果你已经有了弦,这应该很容易做到。

在 for 循环之前声明一个 NSString 对象(或使用 str),并在循环过程中附加到该对象。并且您不应该在代码中声明 str 两次。可能想重命名其中之一。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文