Just temporarily storing some code examples:
- (NSArray *)tokensSeparatedByCharactersFromSet:(NSCharacterSet *)separatorSet
{
NSScanner *scanner = [NSScanner scannerWithString:self];
NSCharacterSet *tokenSet = [separatorSet invertedSet];
NSMutableArray *tokens = [NSMutableArray array];
[scanner setCharactersToBeSkipped:separatorSet];
while (![scanner isAtEnd])
{
NSString *destination = [NSString string];
if ([scanner scanCharactersFromSet:tokenSet intoString:&destination])
{
[tokens addObject:[NSString stringWithString:destination]];
}
}
return [NSArray arrayWithArray:tokens];
}
- (NSArray *)objCTokens
{
NSMutableCharacterSet *tokensSet = [NSMutableCharacterSet alphanumericCharacterSet];
[tokensSet addCharactersInString:@"_:"];
return [self tokensSeparatedByCharactersFromSet:[tokensSet invertedSet]];
}
-(NSString *)removeTabsAndReturns
{
NSMutableString *outputString = [NSMutableString string];
NSCharacterSet *charSet;
NSString *temp;
NSScanner *scanner = [NSScanner scannerWithString:self];
charSet = [NSCharacterSet characterSetWithCharactersInString:@"\n\r\t"];
while ([scanner scanUpToCharactersFromSet:charSet intoString:&temp])
{
[outputString appendString:temp];
}
return [[outputString copy] autorelease];
} |