I'm trying to scan a list of floats from an http page.
The float numbers use:
- "." as 1000 separator
- "," as decimal separator
I've set the locale for the Scanner to correctly recognize the
separators, but it does not work.
The Scanner seems to completely ignore the locale settings.
Here below a simplified version of my code and the correspondent Run Log
What's wrong with my code?
Thanks
Marco
- (IBAction)test:(id)sender
{
NSScanner *theScanner;
NSString *scanString = @"+2.000,56";
float floatValue;
NSMutableDictionary *scannerLocale = [NSMutableDictionary
dictionaryWithCapacity:2];
// Create the Scanner
theScanner = [NSScanner scannerWithString:scanString];
// Set the CharactersToBeSkipped
[theScanner setCharactersToBeSkipped:[NSCharacterSet
characterSetWithCharactersInString:@"+"]];
// Set the locale for the Scanner
[scannerLocale setObject:@"." forKey:NSLocaleGroupingSeparator];
[scannerLocale setObject:@"," forKey:NSLocaleDecimalSeparator];
[theScanner setLocale:scannerLocale];
NSLog(@"Locale Grouping Separator: %@", [[theScanner locale]
objectForKey:NSLocaleGroupingSeparator]);
NSLog(@"Locale Decimal Separator: %@", [[theScanner locale]
objectForKey:NSLocaleDecimalSeparator]);
// Scan the string
if ([theScanner scanFloat:&floatValue]) {
// Add values to the stocksListValues dictionary
NSLog(@"floatValue:%f", floatValue);
} else {
NSLog(@"Scan Error");
}
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden