Ros*_*nal 9 java string android phone-number
我需要比较两个电话号码,以确定它们是否来自同一个发送者/接收者.用户可以向联系人发送消息,该联系人可以回复.
答复通常以
+[country-code][area-code-if-any][and-then-the-actual-number]格式提供.例如,
+94 71 2593276对于斯里兰卡的电话号码.
当用户发送消息时,他通常会以格式输入(对于上面的示例)0712593276(假设他也在斯里兰卡).
所以我需要的是,我需要检查这两个数字是否相同.此应用程序将在国际上使用.所以我不能只用0替换前2位数(那么对于像美国这样的国家来说这将是一个问题).有没有办法在Java或Android专门做到这一点?
谢谢.
Nim*_*007 17
Android有很好的PhoneNumberUtils,我猜您正在寻找:
public static boolean compare (String a, String b)
Run Code Online (Sandbox Code Playgroud)
看看:http: //developer.android.com/reference/android/telephony/PhoneNumberUtils.html
使用它应该看起来像这样:
String phone1
String phone2
if (PhoneNumberUtils.compare(phone1, phone2)) {
//they are the same do whatever you want!
}
Run Code Online (Sandbox Code Playgroud)
小智 10
android.telephony.PhoneNumberUtils class提供几乎所有必要的功能来处理电话号码和标准.
对于您的情况,解决方案是或者.前者检查资源以确定是否使用严格或松散的比较算法,因此在大多数情况下是更好的选择.PhoneNumberUtils.compare(Context context, String number1, String number2)PhoneNumberUtils.compare(String number1, String number2)
PhoneNumberUtils.compare("0712593276", "+94712593276") // always true
PhoneNumberUtils.compare("0712593276", "+44712593276") // always true
// true or false depends on the context
PhoneNumberUtils.compare(context, "0712593276", "+94712593276")
Run Code Online (Sandbox Code Playgroud)
检查该号码是否是接收者号码的子字符串怎么样?
例如,假设我的巴西号码是 888-777-666,您的号码是 111-222-333。要从这里给您打电话,我需要拨打其他号码才能拨打国际电话。假设我需要添加 9999 + your_number,结果是 9999111222333。
如果RawNumber.substring(your_number)回来true我可以说我正在给你打电话。
| 归档时间: |
|
| 查看次数: |
6805 次 |
| 最近记录: |