How to find delimiter in objective C?
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.
精彩评论