Java examples for java.lang:String Format
Convert format phone number.
//package com.java2s; public class Main { public static void main(String[] argv) throws Exception { String phoneNumber = "java2s.com"; System.out.println(convertETFormatPhoneNumber(phoneNumber)); }/*from w w w . ja va2s . co m*/ /** * Convert et format phone number. * * @param phoneNumber the phone number * @return the string */ public static String convertETFormatPhoneNumber(String phoneNumber) { try { if (phoneNumber != null && !"".equals(phoneNumber.trim())) { phoneNumber = phoneNumber.subSequence(0, 3) + "-" + phoneNumber.subSequence(3, 6) + "-" + phoneNumber.subSequence(6, 10); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return phoneNumber; } }