如何判斷NSString是數值類型

#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];
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章