NSArray *arrayOfSeperatedString = [currentLanguage componentsSeparatedByString:@"_"];
NSLog(@"%@", [arrayOfSeperatedString objectAtIndex:0]);
編輯:
一個更好的辦法是:
NSLocale *currentLocale = [[[NSLocale alloc] initWithLocaleIdentifier:currentLanguage] autorelease]; //Sets the what laguage the language name and country name should be written in
NSString *displayNameString = [currentLocale displayNameForKey:NSLocaleIdentifier value:currentLocale]; //Sets what language you want written..
NSLog(@"The current language is: %@", displayNameString);
現在,如果當前的語言是法語(fr_FR時)這將返回:
The current language is: français (France)
如果當前語言是英語(EN_US)這將返回
The current language is: English (United States)
現在,如果你想ommit國名使用componentsSeperatedByString:@" ("
如上所述..
它並不總是奏效。例如,zh_CN與zh_CN完全不同。 – kennytm 2010-09-14 10:13:48