开发者

Cocoa NSString explode

开发者 https://www.devze.com 2022-12-28 15:38 出处:网络
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百科ng

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

精彩评论

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