【问题标题】:Convert international phone number into local one将国际电话号码转换为本地电话号码
【发布时间】:2012-01-09 18:57:19
【问题描述】:

我正在尝试使用 libphonenumber 谷歌库将数字从 国际到本地。

国际号码代表的是:“+97239658320”

本地号码(在以色列是):“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();
    }

但是,在“电话”中,结果是:

Country Code: 972 National Number: 39658320 (without the leading zero)

如何正确转换?

【问题讨论】:

    标签: java android phone-number libphonenumber


    【解决方案1】:

    查看project page 的快速示例说,您在解析后应该有:

    {
    country_code: 972
    national_number: 39658320
    }
    

    要获得您想要的格式,您应该使用格式NATIONAL

    phoneUtil.format(phone, PhoneNumberFormat.NATIONAL)
    

    要去除任何电话号码分隔符,请查看 stripSeparators()android.telephony.PhoneNumberUtils

    【讨论】:

    • 谢谢!结果现在是:03-965-8320。我将手动删除连字符:D
    猜你喜欢
    • 1970-01-01
    • 2015-01-19
    • 2016-04-05
    • 1970-01-01
    • 2011-01-16
    • 2012-01-14
    • 1970-01-01
    • 1970-01-01
    • 2016-07-27
    相关资源
    最近更新 更多