NSScanner confusion
NSScanner confusion
- Subject: NSScanner confusion
- From: "Marcus S. Zarra" <email@hidden>
- Date: Tue, 7 Feb 2006 22:58:50 -0700
In this code sample:
NSScanner *lineScanner = nil;
NSScanner *fileScanner = [NSScanner scannerWithString: data];
NSString *line;
NSString *value;
NSCharacterSet *commaTabSet = [NSCharacterSet
characterSetWithCharactersInString:@",\t"];
while([fileScanner scanUpToCharactersFromSet: [NSCharacterSet
controlCharacterSet] intoString: &line]) {
NSLog(@"Line: %@", line);
if (lineScanner) [lineScanner release];
lineScanner = [[NSScanner alloc] initWithString:line];
while ([lineScanner scanUpToCharactersFromSet:commaTabSet
intoString:&value]) {
NSLog(@"Value: '%@'", value);
if (![lineScanner isAtEnd]) [lineScanner setScanLocation:
([lineScanner scanLocation] + 1)];
}
}
if (lineScanner) [lineScanner release];
Assuming that the contents of the variable 'data' is a csv file, why
do I need to increment the scan location to jump over the comma or
tab? Just started working with NSScanner thanks to a suggestion from
the list and this is baffling me. The first while seems to jump over
the line endings just fine but the loop over the elements in a line
stops dead at the comma/tab.
Any tips would be greatly appreciated.
Marcus
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden