Re: NSScanner problem
Re: NSScanner problem
- Subject: Re: NSScanner problem
- From: Drew McCormack <email@hidden>
- Date: Tue, 27 Nov 2001 09:35:36 +0100
I'm not sure if this is right, Paul, but perhaps "scanUpToString:" only
moves the scanner to within white space of the string, the same way that
"isAtEnd" returns YES when there is only whitespace left to scan.
The way I would do this is like this:
[scanner scanInt: &i1];
[scanner scanInt: &i2];
[scanner scanString:@"\"" intoString:nil];
[scanner scanUpToString: @"\"" intoString: &s3];
[scanner scanString:@"\""];
etc.
Note that the scanner will skip any whitespace before the thing it is to
scan. So the first call to "scanString:" skips all the whitespace and
then scans in the quote symbol.
Hope this helps,
Drew McCormack
On Friday, November 23, 2001, at 04:32 , Paul Ferguson wrote:
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/>
_______________________________________________
cocoa-dev mailing list
email@hidden
http://www.lists.apple.com/mailman/listinfo/cocoa-dev