Advertisement
drSdGdBy

formating phonenumber

Apr 5th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.52 KB | None | 0 0
  1. long phoneFmt = 123456789L;
  2. //get a 12 digits String, filling with left '0' (on the prefix)  
  3. DecimalFormat phoneDecimalFmt = new DecimalFormat("0000000000");
  4. String phoneRawString= phoneDecimalFmt.format(phoneFmt);
  5.  
  6. java.text.MessageFormat phoneMsgFmt=new java.text.MessageFormat("({0})-{1}-{2}");
  7.     //suposing a grouping of 3-3-4
  8. String[] phoneNumArr={phoneRawString.substring(0, 3),
  9.           phoneRawString.substring(3,6),
  10.           phoneRawString.substring(6)};
  11.  
  12. System.out.println(phoneMsgFmt.format(phoneNumArr));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement