FROM : Simone Manganelli
DATE : Sun Nov 03 19:34:01 2002
I'm having a few more problems that I need to figure out, if someone
can help me out.
I'm trying to use an NSScanner to scan a string and see if it contains
a substring. I have an array of strings that I want to search for in
each string, and if any of them are present, then I want to set a flag.
Here's the code:
NSScanner *scanner;
NSMutableArray *arrayOfValues = [[NSUserDefaults
standardUserDefaults] objectForKey:@"User-Defined Values"];
int i;
int j;
BOOL flag = NO;
for (i=0; i < [processArray count]; i++) {
scanner = [NSScanner scannerWithString:[[processArray
objectAtIndex:i] processName]];
for (j=0; j < [arrayOfValues count]; j++) {
NSLog(@"%@",[[processArray objectAtIndex:i] processName]);
NSLog(@"%@",[arrayOfValues objectAtIndex:j]);
if ([scanner scanString:[arrayOfValues objectAtIndex:j]
intoString:nil]) { flag = YES; }
if (flag) {NSLog(@"YES!");}
}
}
The problem is, the NSScanner returns sets the flag as YES for each
step. That is, every time the log displays the processName and the
scanString, it always returns a YES, regardless of whether processName
actually contains scanString or not.
Am I doing something wrong here?
Thanks for any help.
-- Simone Manganelli
DATE : Sun Nov 03 19:34:01 2002
I'm having a few more problems that I need to figure out, if someone
can help me out.
I'm trying to use an NSScanner to scan a string and see if it contains
a substring. I have an array of strings that I want to search for in
each string, and if any of them are present, then I want to set a flag.
Here's the code:
NSScanner *scanner;
NSMutableArray *arrayOfValues = [[NSUserDefaults
standardUserDefaults] objectForKey:@"User-Defined Values"];
int i;
int j;
BOOL flag = NO;
for (i=0; i < [processArray count]; i++) {
scanner = [NSScanner scannerWithString:[[processArray
objectAtIndex:i] processName]];
for (j=0; j < [arrayOfValues count]; j++) {
NSLog(@"%@",[[processArray objectAtIndex:i] processName]);
NSLog(@"%@",[arrayOfValues objectAtIndex:j]);
if ([scanner scanString:[arrayOfValues objectAtIndex:j]
intoString:nil]) { flag = YES; }
if (flag) {NSLog(@"YES!");}
}
}
The problem is, the NSScanner returns sets the flag as YES for each
step. That is, every time the log displays the processName and the
scanString, it always returns a YES, regardless of whether processName
actually contains scanString or not.
Am I doing something wrong here?
Thanks for any help.
-- Simone Manganelli
| Related mails | Author | Date |
|---|---|---|
| No related mails found. | ||






Cocoa mail archive

