Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Split NSString with multiple delimiters?

For text bozo__foo!!bar.baz, how to split an NSString containing this into (bozo, foo, bar, baz)?

That is, separe it in components with strings (delimiters) __, !! and ..

like image 449
Matoe Avatar asked Nov 22 '12 19:11

Matoe


1 Answers

You can split the strings using NSCharacterSet. Try this

NSString *test=@"bozo__foo!!bar.baz";
NSString *sep = @"_!.";
NSCharacterSet *set = [NSCharacterSet characterSetWithCharactersInString:sep];
NSArray *temp=[test componentsSeparatedByCharactersInSet:set];
NSLog(@"temp=%@",temp);
like image 73
prakhar Avatar answered Oct 15 '22 12:10

prakhar