NSScanner is stripping leading spaces?
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:¤tRecord]) {}
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