按空格数拆分 NSString [英] Split NSString by number of whitespaces
本文介绍了按空格数拆分 NSString的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 NSString
,其中包含一些由未知数量的空白字符分隔的值.例如:
I have an NSString
that contains some values separated by an unknown number of whitespace characters. For example:
NSString* line = @"1 2 3";
我想将 NSString
拆分为一个 NSArray
值,如下所示:{@"1", @"2", @"3"}
.
I would like to split the NSString
into an NSArray
of values like so: {@"1", @"2", @"3"}
.
推荐答案
获取由 @" "
分隔的组件,并从结果中删除所有类似 @""
的对象数组.
Get the components separated by @" "
and remove all objects like @""
from the resultant array.
NSString* line = @"1 2 3";
NSMutableArray *array = (NSMutableArray *)[line componentsSeparatedByString:@" "];
[array removeObject:@""]; // This removes all objects like @""
这篇关于按空格数拆分 NSString的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文