【发布时间】:2018-06-01 17:05:46
【问题描述】:
我正在使用国家代码选择器库供用户选择国家。
我用国家名称(即:新加坡)存储了选定的项目。
现在我想将国家名称转换为 ISO Alpha 2 国家代码(即:sg)。
我正在使用区域设置,但它不起作用,我缺少什么?
public String getCountryCodeFromName(String countryName){
Locale locale = new Locale("",countryName);
String countryCode = locale.getCountry().toLowerCase();
return countryCode;
}
【问题讨论】:
-
你用谷歌搜索了吗?
-
代码是谷歌搜索后创建的,但似乎我错过了使用 String[] isoCountryCodes = Locale.getISOCountries();
-
您似乎在 google 搜索到的第一个结果时就停了下来。
标签: android locale country-codes