Last active
December 18, 2018 22:29
-
-
Save rodrigordgfs/511736e0b786c8a1336ae1add3805e28 to your computer and use it in GitHub Desktop.
Mask Phone to TextView
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static String addMask(final String textoAFormatar, final String mask){ | |
String formatado = ""; | |
int i = 0; | |
// vamos iterar a mascara, para descobrir quais caracteres vamos adicionar e quando... | |
for (char m : mask.toCharArray()) { | |
if (m != '#') { // se não for um #, vamos colocar o caracter informado na máscara | |
formatado += m; | |
continue; | |
} | |
// Senão colocamos o valor que será formatado | |
try { | |
formatado += textoAFormatar.charAt(i); | |
} catch (Exception e) { | |
break; | |
} | |
i++; | |
} | |
return formatado; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment