Last active
March 10, 2018 18:31
-
-
Save williaanlopes/5364e8c576a1e22df63ece6869167044 to your computer and use it in GitHub Desktop.
Comparar duas Strings ignorando maiúsculas, minúsculas e acentos (Português)
This file contains 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
// Vamos comparar duas strings ignorando os acentos. | |
String st1 = "Gisele da Conceição Zózima Bündchen"; | |
String st2 = "Gisele da Conceicao Zozima Bundchen"; | |
String st3 = "GISELE DA CONCEICAO ZÓZIMA BUNDCHEN"; | |
String st4 = "Gisele da Conceicao Zozimo Bundchen"; // note que esta string é diferente | |
Collator collator = Collator.getInstance (new Locale ("pt", "BR")); | |
collator.setStrength(Collator.PRIMARY); // importante! | |
if (collator.compare (st1, st2) == 0) { | |
System.out.println ("As duas Giseles são a mesma pessoa, só diferem pelos acentos"); | |
} | |
if (collator.compare (st1, st3) == 0) { | |
System.out.println ("As duas Giseles são a mesma pessoa, só diferem pelos acentos e pela diferença de caixa"); | |
} | |
if (collator.compare (st1, st4) != 0) { | |
System.out.println ("As duas Giseles não são a mesma pessoa"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment