本文介绍了在Android中格式化电话号码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试了以下代码来格式化android中的电话号码:-
I tried the following code to format phone number in android:-
public static String formatPhoneNumber(String number){
return PhoneNumberUtils.formatNumber(number);
}
我正在将"19253951646"传递给该函数.它以1-925-395-1646的格式返回文本.我想要格式为1(925)395-1646的结果.任何帮助将不胜感激.
I am passing "19253951646" to the function..It returns the text in the format 1-925-395-1646.I want the result in the format 1(925)395-1646.Any help would be highly apprciated.
推荐答案
编写了自己的函数来格式化数字.
Wrote my own function to format the number.
public static String formatPhoneNumber(String number){
number = number.substring(0, number.length()-4) + "-" + number.substring(number.length()-4, number.length());
number = number.substring(0,number.length()-8)+")"+number.substring(number.length()-8,number.length());
number = number.substring(0, number.length()-12)+"("+number.substring(number.length()-12, number.length());
return number;
}
这篇关于在Android中格式化电话号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!