discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Another question about NSScanner...


From: Frederic
Subject: Another question about NSScanner...
Date: Thu, 25 Jan 2001 00:07:24 +0100

Hello again :)

Could you please take a look at the following code and see if the ouput
(below) is the
one expected?

NSString* str = @"a{b} {aa}{}{\n}a";
NSScanner* scanner = [NSScanner scannerWithString:str];
NSCharacterSet *leftset = [NSCharacterSet
characterSetWithCharactersInString:@"{"];
NSCharacterSet *rightset = [NSCharacterSet
characterSetWithCharactersInString:@"}"];
        
NSLog( @"str length=%d", [str length] );
while ([scanner isAtEnd] == NO)
{
        if ([scanner scanUpToCharactersFromSet:leftset intoString:nil])
        {
                NSLog( @"found { at %d", [scanner scanLocation] );
                if ([scanner scanUpToCharactersFromSet:rightset intoString:nil])
                {
                        NSLog( @"found } at %d", [scanner scanLocation] );
                }
        }
        NSLog( @"At %d", [scanner scanLocation] );
}

Output:
str length=15
found { at 1
found } at 3
At 3
found { at 5
found } at 8
At 8
found { at 9
found } at 10
At 10
found { at 11
found } at 13
At 13
found { at 15
At 15

I dont understand the last "{" match.
Any though?
Frederic



reply via email to

[Prev in Thread] Current Thread [Next in Thread]