Use [NSNumberFormatter numberFromString: s]
. It returns nil if the specified string is non-numeric. You can configure the NSNumberFormatter to define "numeric" for your particular scenario.
#import <Foundation/Foundation.h>
int
main(int argc, char* argv[])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSLocale *l_en = [[NSLocale alloc] initWithLocaleIdentifier: @"en_US"];
NSLocale *l_de = [[NSLocale alloc] initWithLocaleIdentifier: @"de_DE"];
NSNumberFormatter *f = [[NSNumberFormatter alloc] init];
[f setLocale: l_en];
NSLog(@"returned: %@", [f numberFromString: @"1.234"]);
[f setAllowsFloats: NO];
NSLog(@"returned: %@", [f numberFromString: @"1.234"]);
[f setAllowsFloats: YES];
NSLog(@"returned: %@", [f numberFromString: @"1,234"]);
[f setLocale: l_de];
NSLog(@"returned: %@", [f numberFromString: @"1,234"]);
[l_en release];
[l_de release];
[f release];
[pool release];
}