• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSScanner confusion
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • [SOLVED] Re: NSScanner confusion
      • From: "Marcus S. Zarra" <email@hidden>
  • Prev by Date: [EOT as said...] Re: a c question
  • Next by Date: [SOLVED] Re: NSScanner confusion
  • Previous by thread: Re: Universal Binary Screensavers in 10.3?
  • Next by thread: [SOLVED] Re: NSScanner confusion
  • Index(es):
    • Date
    • Thread