[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
NSScanner can't scan ']' properly ?
From: |
Yen-Ju Chen |
Subject: |
NSScanner can't scan ']' properly ? |
Date: |
Sun, 20 Apr 2003 18:21:24 -0400 |
I try to use NSScanner to count the number of '{', '}', '[', '\n', etc.,
and the result is unexpected.
It happens specially for ']' and ')'.
Below is a test code.
Did I do something wrong ?
I also try scanString rather than scanUpToString, and it got worse.
Is there any limitation for NSScanner, such as special character ?
Thanx.
Yen-Ju
#include <AppKit/AppKit.h>
int main(int argc, const char *argv[])
{
NSAutoreleasePool *pool = [NSAutoreleasePool new];
NSString *string = [NSString stringWithContentsOfFile: @"NSMatrix.m"];
NSScanner *scanner = [NSScanner scannerWithString: string];
NSString *ch = @"[";
BOOL result = YES;
unsigned location = 0;
unsigned total = 0;
while(result)
{
[scanner setScanLocation: location];
result = [scanner scanUpToString: ch intoString: NULL];
location = [scanner scanLocation];
if (location >= [string length])
break;
location++;
total++
}
NSLog(@"total %d", total);
RELEASE(pool);
return 0;
}
_________________________________________________________________
MSN 8 helps eliminate e-mail viruses. Get 2 months FREE*.
http://join.msn.com/?page=features/virus
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- NSScanner can't scan ']' properly ?,
Yen-Ju Chen <=