我可以通过电话获得联系电话.我想知道如何从中删除国家/地区代码.也就是说,如果用户的电话号码带有国家代码(+ 91-9876543210),我需要没有带前缀国家代码的电话号码(9876543210).
提前致谢.
Ye *_*ung 23
我建议使用libphonenumber轻松解析电话号码.您可以通过这种方式拆分国家/地区代码和电话号码.
try {
// phone must begin with '+'
PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
Phonenumber.PhoneNumber numberProto = phoneUtil.parse("+91-9876543210", "");
int countryCode = numberProto.getCountryCode();
long nationalNumber = numberProto.getNationalNumber();
Log.i("code", "code " + countryCode);
Log.i("code", "national number " + nationalNumber);
} catch (NumberParseException e) {
System.err.println("NumberParseException was thrown: " + e.toString());
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6501 次 |
| 最近记录: |