来自NSArray的NSString [英] NSString from NSArray

查看:102
本文介绍了来自NSArray的NSString的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从Array.But创建一个String,有条件生成它,如下所述。

I am trying to create a String from Array.But, there is condition to how it should be generated, as explained below.

NSArray *array=[NSArray arrayWithObjects:@"Hello",@"World",nil];
[array componentsJoinedByString:@","];

这将输出:Hello,World。

This will output: Hello,World.

但是,如果第一个项目是空的,那么是否有办法接收唯一的第二个。

But, if first Item is Empty,then is there way to receive the only second one.


  1. 你好,@=>您好

  2. @,World => World

  3. Hello,World => Hello,World


推荐答案

另一种方法是获取数组的可变副本并删除无效对象。这样的事情可能是:

Another way to do this is to grab a mutable copy of the array and just remove non valid objects. Something like this perhaps:

NSMutableArray *array = [[NSArray arrayWithObjects:@"",@"World",nil] mutableCopy];
[array removeObject:@""]; // Remove empty strings
[array removeObject:[NSNull null]]; // Or nulls maybe

NSLog(@"%@", [array componentsJoinedByString:@","]);

这篇关于来自NSArray的NSString的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆