NSScanner problem
NSScanner problem
- Subject: NSScanner problem
- From: Paul Ferguson <email@hidden>
- Date: Fri, 23 Nov 2001 07:32:01 -0800
- Resent-date: Mon, 26 Nov 2001 11:01:30 -0800
- Resent-from: Paul Ferguson <email@hidden>
- Resent-message-id: <email@hidden>
- Resent-to: email@hidden
I have been unable to resolve a problem I'm having with NSScanner.
I have a string like this:
NSString * foo = @"1 2 \"three\"\"four\"";
which I want to scan into two ints and two NSStrings:
NSScanner scanner = [[NSScanner alloc] initWithString: foo];
[scanner scanInt: &i1];
[scanner scanInt: &i2];
[scanner scanUpToString: @"\"" intoString: nil]; // <-- here is the
problem
[scanner setScanLocation: [scanner scanLocation]+1];
[scanner scanUpToString: @"\"" intoString: &s3];
[scanner setScanLocation: [scanner scanLocation]+1];
[scanner scanUpToString: @"\"" intoString: nil];
[scanner setScanLocation: [scanner scanLocation]+1];
[scanner scanUpToString: @"\"" intoString: &s4];
The problem is that the scanUpToString:intoString: method never moves
the scanner's scanLocation, it remains where it was after the second
scanInt: call. It seems that scanUpToString:intoString: should change
the scan location, which it does if you substitute another string for
@"\"" in my example (regardless of whether that string occurs in foo.)
I've tried using scanUpToCharactersFromSet:intoString: as well, and it
makes no difference.
Thanks,
<fergy/>