[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Question about NSScanner usage
From: |
Richard Frith-Macdonald |
Subject: |
Re: Question about NSScanner usage |
Date: |
Fri, 26 Jan 2001 05:03:23 +0000 |
On Wednesday, January 24, 2001, at 09:36 PM, Frederic wrote:
> Hi,
>
> Is it normal that the following code runs into a cpu loop
> indefinitively?
> I would except to find 3 "a" ...
>
> NSString* str = @"a a a";
> NSScanner* scanner = [NSScanner scannerWithString:str];
> NSCharacterSet *set = [NSCharacterSet
> characterSetWithCharactersInString:@"a"];
> while ([scanner isAtEnd] == NO)
> {
> if ([scanner scanUpToCharactersFromSet:set intoString:nil])
> {
> NSLog( @"found a" );
> }
> }
Yes that's normal - you are repeatedly scanning up to the first 'a',
but never scanning the letter 'a' itsself.
You need a [scanner scanString @"a" intoString: 0] where your NSLog() is.