NSScanner stoopid question
NSScanner stoopid question
- Subject: NSScanner stoopid question
- From: Koen van der Drift <email@hidden>
- Date: Fri, 4 Apr 2003 21:34:36 -0500
Hi,
I am scanning a string for a specific character. However, if the next
character belongs to another NSCharacterSet, I should not continue with the
algorithm.
Here's a snippet:
NSScanner *scanner = [NSScanner scannerWithString: myString];
int len = [myString length];
int current;
while (![scanner isAtEnd])
{
[scanner scanUpToCharactersFromSet: firstSet intoString:nil];
current = [scanner scanLocation];
if ( len != current + 1 )
{
if ( ![restrictionSet characterIsMember:
[myString characterAtIndex: current + 1 ]])
{
...
}
}
}
So I first test if the current position is past the length of the string
before I test the character at current + 1.
However, if current happens to be len, then (len != current + 1) is false
and the following line give and "[NSCFString characterAtIndex:]: Range or
index out of bounds" error.
There probably must a very simple solution for this, but I fail to see it :(
I have been sitting too long in the sun and staring too long at my screen,
and can't figure out how to solve this, so any help is appreciated.
thanks,
- Koen.
_______________________________________________
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.