3
I got a flea behind my ear.
I have a method that removes / changes some characters from the string, it is 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 repeats itself for several and several lines and besides causing a loss in performance I am suspicious of memory Leak.
Is there any more elegant / functional way to do this ?
Follow the list of all 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.
Ever tried to make a regex? What other items do you need to replace besides the 3 mentioned?
– user28595
I haven’t tried/thought about it yet. I need to remove/change several other "special" characters : ö > o , ª > a , never do something like á > empty , because I need the complete string only with them modified.
– Mateus Veloso