NSScanner reads the correct number but the number isn't added to an array
NSScanner reads the correct number but the number isn't added to an array
- Subject: NSScanner reads the correct number but the number isn't added to an array
- From: Philip Riggs <email@hidden>
- Date: Sun, 14 Dec 2003 10:21:52 -0700
Using the following code:
NSString * numbers = [[NSString alloc] initWithFormat:@"SET {1.1, 2.2,
3.3, 4.4}"];
NSScanner * aScanner = [NSScanner scannerWithString:numbers];
[aScanner setCharactersToBeSkipped: [NSCharacterSet
characterSetWithCharactersInString:@" ,SET{}"]];
NSMutableArray * numberArray = [[NSMutableArray alloc] init];
BOOL success = TRUE;
while (success)
{
double newNumber = 0.0;
if ([aScanner scanDouble:&newNumber])
{
NSLog (@"newNumber = %f", newNumber);
[numberArray addObject:[NSNumber numberWithDouble:newNumber]];
}
else
success = FALSE;
}
int counter;
for (counter = 0; counter < [numberArray count]; counter++)
NSLog(@"Number %d :: %f", counter, [numberArray
objectAtIndex:counter]);
But gives the output:
newNumber = 1.100000
newNumber = 2.200000
newNumber = 3.300000
newNumber = 4.400000
Number 0 :: 0.000000
Number 1 :: 0.000000
Number 2 :: 0.000000
Number 3 :: 0.000000
Why doesn't numberArray add the correct number?
Thanks!
Philip D Riggs
_______________________________________________
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.