开发者

Cocoa NSString explode

I have a NSString: @"1a,1b,1c,1d,5c". I want this NSString separated into a NSMutableArray, but I don't know how. I think it is fairly simple but I can't find it (maybe because my E开发者_Go百科nglish isn't good enough to find a good description for it to search on).

Regards, Dodo


NSString *_stringToSplit = @"1a,1b,1c,1d,5c";
NSArray *_splitItems = [_stringToSplit componentsSeparatedByString:@","];
NSMutableArray *_mutableSplitItems = [NSMutableArray arrayWithCapacity:[_splitItems count]]; 
[_mutableSplitItems addObjectsFromArray:_splitItems];


[NSMutableArray arrayWithArray:[string componentsSeparatedByString:@","]];


Use -componentsSeparatedByString: to explode.

The returned value is an NSArray. If you need an NSMutableArray, call the -mutableCopy method on it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜