• 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 is stripping leading spaces?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSScanner is stripping leading spaces?


  • Subject: NSScanner is stripping leading spaces?
  • From: "Timothy Reaves" <email@hidden>
  • Date: Tue, 25 Aug 2009 21:00:42 -0400 (EDT)
  • Importance: Normal

     I have a character set; I've tried both
NSCharacterSet *newlineSet = [NSCharacterSet
characterSetWithCharactersInString:@"\n"];
and
NSCharacterSet *newlineSet = [NSCharacterSet newlineCharacterSet];

     I use this to read lines from a file, like so:
while ([scanner scanUpToCharactersFromSet:newlineSet
intoString:&currentRecord]) {}

     I then read out substrings from currentRecord like so:
someNumber = [NSNumber numberWithInt:[[currentRecord
substringWithRange:NSMakeRange(0, 6)] intValue]];
someOtherNumber = [[currentRecord substringWithRange:NSMakeRange(14, 2)]
intValue];

     The file looks like:
"   455| | | 3| 1|  \n118222| |P| 2| 1|  "

     The issue is, someNumber always is the correct number, but
someOtherNumber is not;  it is always zero.  If I use an NSString, I
see that it is being set to two spaces (the last two spaces in the
record).  For the second record, both are correct.  So it appears
that the first three spaces in the first record are being ignored.
This is confirmed by printing the length of each record; the first
record is three shorter.

     Does anyone have any idea why this is going on?  The trailing spaces
are being counted correctly.



_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: NSScanner is stripping leading spaces?
      • From: Graham Cox <email@hidden>
  • Prev by Date: Re: Normalize an NSAttributedString
  • Next by Date: QuickTime Animation Rendering
  • Previous by thread: Re: Beware: trivially reproducible NSPersistentDocument crash when saving
  • Next by thread: Re: NSScanner is stripping leading spaces?
  • Index(es):
    • Date
    • Thread