Reputation: 5404
I'm trying to use libphonenumber
google library to convert a number from
international to local.
The international number represent is: "+97239658320"
The local number (here in Israel is): "039658320"
http://code.google.com/p/libphonenumber/
PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
PhoneNumber phone = null;
try
{
phone = PhoneNumberUtil.getInstance().parse("+97239658320", null);
}
catch (NumberParseException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
however, in "phone" the results are:
Country Code: 972 National Number: 39658320 (without the leading zero)
how do I convert it correctly?
Upvotes: 1
Views: 6500
Reputation: 2398
Looking at the quick example of the project page says that you after parsing should have:
{
country_code: 972
national_number: 39658320
}
To get it in your desired format you should format it with format NATIONAL
:
phoneUtil.format(phone, PhoneNumberFormat.NATIONAL)
To strip out any phone number separators take a look at stripSeparators() from android.telephony.PhoneNumberUtils
Upvotes: 3