简体   繁体   English

如何从电话号码中删除“+”和国家/地区代码?

[英]How do I remove the “+” and country code from a phone number?

I am using following API to get a phone number; 我正在使用以下API来获取电话号码; however, some of the device will return the number in following format: 但是,某些设备将以下列格式返回数字:

"+" + countrycode + phone number Ex. “+”+国家代码+电话号码Ex。 +12062436969 12062436969

TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
String phoneNumber = tm.getLine1Number();

I would like to find out a way/algorithm to remove this "+" sign and the country code, so I will get only the last ten digits. 我想找出一种方法/算法来删除这个“+”符号和国家代码,所以我只得到最后十位数字。 Ex. 防爆。 +12062436969 -> 2062436969 +12062436969 - > 2062436969

I believe I only need the last ten digits. 我相信我只需要最后十位数字。 could anyone please suggest any idea? 任何人都可以建议任何想法?

You should definitely have a look at this amazing library : 你一定要看看这个神奇的图书馆:

http://code.google.com/p/libphonenumber/ http://code.google.com/p/libphonenumber/
https://github.com/googlei18n/libphonenumber https://github.com/googlei18n/libphonenumber

This will solve your problem and might even help you more since you are doing telephony stuff. 这将解决您的问题,甚至可能会帮助您,因为您正在做电话。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM