roll my own method to separate a string into components

This commit is contained in:
Mitchell Livingston 2011-09-19 01:37:43 +00:00
parent 95126c5505
commit 2389bbd49b
1 changed files with 22 additions and 2 deletions

View File

@ -184,8 +184,28 @@
- (NSArray *) betterComponentsSeparatedByCharactersInSet: (NSCharacterSet *) separator - (NSArray *) betterComponentsSeparatedByCharactersInSet: (NSCharacterSet *) separator
{ {
NSMutableArray * components = [NSMutableArray arrayWithArray: [self componentsSeparatedByCharactersInSet: separator]]; NSMutableArray * components = [NSMutableArray array];
[components removeObject: @""];
for (NSUInteger i = 0; i < [self length];)
{
const NSRange range = [self rangeOfCharacterFromSet: separator options: 0 range: NSMakeRange(i, [self length]-i)];
if (range.location != i)
{
NSUInteger length;
if (range.location == NSNotFound)
length = [self length] - i;
else
length = range.location - i;
[components addObject: [self substringWithRange: NSMakeRange(i, length)]];
if (range.location == NSNotFound)
break;
i += length + range.length;
}
}
NSLog(@"%@", components);
return components; return components;
} }