• 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
[SOLVED] Re: NSScanner confusion
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[SOLVED] Re: NSScanner confusion


  • Subject: [SOLVED] Re: NSScanner confusion
  • From: "Marcus S. Zarra" <email@hidden>
  • Date: Tue, 7 Feb 2006 23:03:25 -0700

Figured it out right after giving up.

The answer is that the new line characters are in the default list of characters to be skipped. Comma and tab are not. By adding the following line right after the alloc of the line scanner:

[lineScanner setCharactersToBeSkipped:commaTabSet];

It works without having to jump over the delimiter.

On Feb 7, 2006, at 10:58 PM, Marcus S. Zarra wrote:

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

References: 
 >NSScanner confusion (From: "Marcus S. Zarra" <email@hidden>)

  • Prev by Date: NSScanner confusion
  • Next by Date: Re: Universal Binary Screensavers in 10.3?
  • Previous by thread: NSScanner confusion
  • Next by thread: Crash when color well panel is open
  • Index(es):
    • Date
    • Thread