public void setPhone(String phone) { this.phone = formaterPhone(phone); } private String formaterPhone(String s){ StringBuilder sb = new StringBuilder(); sb.append(s.substring(0, 3)); sb.append("/"); sb.append(s.substring(3, 5)); sb.append("."); sb.append(s.substring(5, 7)); sb.append("."); sb.append(s.substring(7, 9)); return sb.toString(); }
public void setFirstName(String firstName) { this.firstName = formater(firstName); } private String formater(String s){ String res = ""; if(s!=null && s.length()>0){ String res = s.charAt(0)+""; res = res.toUpperCase(); if(s.length()>1){ res = res + s.substring(1).toLowerCase(); } } return res; }
public void setPhone(String phone) { this.phone = phone ; if (phone.length() == 0) { phone = phone.substring(0,4).concat("/"); phone = phone.substring(4,6).concat("."); phone = phone.substring(6,8).concat("."); phone = phone.substring(8,10).concat("."); } System.out.println(phone); }
if (phone.length() == 0)
if (phone.length() != 0)
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionpublic void setPhone(String phone) { this.phone = formaterPhone(phone); } private String formaterPhone(String s){ String res = s; if (res!=null && res.length()>9){ //Je ne comprends pas bien ce que tu fais dans ces lignes //C'est forcément faux res = res.substring(0,4).concat("/"); res = res.substring(4,6).concat("."); res = res.substring(6,8).concat("."); res = res.substring(8,10).concat("."); } System.out.println(phone); }
res = res.substring(0,4).concat("/"); //Taille de res : 5 : 4 premeirs caracteres de res plus / //Et tu demandes de récupérer les caracteres 4,5 et 6 donc erreur res = res.substring(4,6).concat("."); res = res.substring(6,8).concat("."); res = res.substring(8,10).concat(".");