roll my own method to separate a string into components
This commit is contained in:
parent
95126c5505
commit
2389bbd49b
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue