I have a flea behind my ear.
I have a method that removes / changes some characters from the string, it's something like this:
public static String replaceCharSet(String texto) {
texto = texto.replace("&", "E");
texto = texto.replace("$", "S");
texto = texto.replace("á", "a");
................
return texto;
}
Well this is repeated over several lines and in addition to causing a loss in performance I'm suspicious of memory leak.
Is there any more elegant / functional way to do this?
Here is the list of all the characters I need to edit / modify:
"&", "E"
"$", "S"
"ç", "c"
"Ç", "C"
"á", "a"
"Á", "A"
"à", "a"
"À", "A"
"ã", "a"
"Ã", "A"
"â", "a"
"Â", "A"
"ä", "a"
"Ä", "A"
"é", "e"
"É", "E"
"è", "e"
"È", "E"
"ê", "e"
"Ê", "E"
"ë", "e"
"Ë", "E"
"í", "i"
"Í", "I"
"ì", "i"
"Ì", "I"
"î", "i"
"Î", "I"
"ï", "i"
"Ï", "I"
"ó", "o"
"Ó", "O"
"ò", "o"
"Ò", "O"
"õ", "o"
"Õ", "O"
"ô", "o"
"Ô", "O"
"ö", "o"
"Ö", "O"
"ú", "u"
"Ú", "U"
"ù", "u"
"Ù", "U"
"û", "u"
"Û", "U"
"ü", "u"
"Ü", "U"
"º", "o"
"ª", "a"
"-", " "
".", " "
I use JAVA 8, unable to migrate at the moment to other versions. It is an old code here of the company that I want to improve.