开发者

How to find delimiter in objective C?

开发者 https://www.devze.com 2023-01-13 18:57 出处:网络
I have a string : NSString *s = @\"a+v+c+d\"; Where \'+\'开发者_JAVA技巧 is the delimiter. I want to store each a,b,c,d in array. How can it be done in objective C?- (NSArray *)componentsSeparated

I have a string :

NSString *s = @"a+v+c+d";

Where '+'开发者_JAVA技巧 is the delimiter.

I want to store each a,b,c,d in array. How can it be done in objective C?


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

is the method you are looking for

NSArray *yourArray = [yourString componentsSeparatedByString:@"+"];


-[NSString componentsSeparatedByString:] returns a, v, c, d as elements in an NSArray. Use -[NSString componentsSeparatedByCharactersInSet:] if you have more than one delimiter.

0

精彩评论

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

关注公众号