简体   繁体   中英

how to split string into NSMutableArray

I want to split string into NSMutableArray

I know

- (NSArray *)componentsSeparatedByString:(NSString *)separator

is available but this one is for NSArray not for NSMutableArray .

I need because after spliting i want to remove element from array by using

-(void)removeObjectAtIndex:(NSUInteger)index

which is not possible with NSArray.

Thank you

You can also just get a mutable copy of the returned array:

NSMutableArray *array = [[myString componentsSeparatedByString:@"..."] mutableCopy];

Also, remember that copy, like alloc, does allocate new memory. So when used in non-ARC code you must autorelease the copied array or manually release it when you are done with it.

Make a new NSMutableArray using

NSArray *array = [NSString componentsSeparatedByString:@"..."];
NSMutableArray *mutable = [NSMutableArray arrayWithArray:array];

从由componentsSeparatedByString创建的输出NSArray创建一个NSMutableArray。

NSMutableArray *mutableArray = [[NSMutableArray alloc] initWithArray:array]; 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM