Re: NSScanner woes
Re: NSScanner woes
- Subject: Re: NSScanner woes
- From: "Louis C. Sacha" <email@hidden>
- Date: Tue, 25 May 2004 00:16:30 -0700
Hello...
Did you use setCharactersToBeSkipped: to change the characters that
are skipped in front of anything that is being scanned?
By default, it is the "whitespace and newline" character set, which
means that the scanner would automatically skip the characters from
the string you are trying to scan.
What I think is happening is that scanString:intoString: is skipping
past the \r\n and checking the next characters. Since they don't
match the string you have provided, it is returning FALSE/NO, and the
scan location isn't advancing.
So, all you would have to do is either:
1) stop trying so hard to scan past the \r\n since it will happen
automatically when you scan the next value :)
or
2) change the characters to be skipped to just the "whitespace"
character set if you need to scan past the newline stuff manually for
some reason.
Note that the "characters to be skipped" are only skipped at the
beginning of the scan, so they generally don't interfere with
anything else.
Hope that helps,
Louis
Hello,
I have a scanner with its scan location right before a "\r\n". I'm
trying to scan past it but am having problems.
Originally I just did a [scanner scanString:@"\r\n" intoString:nil],
but it didn't scan past it as I expected.
if (! [scanner scanString:@"\r\n" intoString:nil]) {
if ([[str substringWithRange:NSMakeRange([scanner
scanLocation],2)] isEqualToString:@"\r\n"]) {
NSLog(@"this should never happen");
}
}
//Where "str" is the string I created the scanner with.
Sure enough, the NSLog message gets printed. The second 'if' shows
that there is, indeed, a "\r\n" at the scan location... but it's not
getting scanned.
What gives? Any ideas? I'm assuming that I'm missing something
painfully obvious, and hopefully somebody here can pick it up.
Thanks,
Mark A. Stratman
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.