I am writing a program and I need to replace some words with others, but sometimes the words can be similar.
Words do not have spaces, and they are always complete words.
Example:
String[] palabrasAcambiar = {"pan","pan2"};
String[] valores = {"pan1","pan2"};
String oracion = "el pan es mejor que el pan2";
//REEMPLAZAR PALABRAS POR VALORES
for (int i = 0; i < 2; i++) {
oracion = oracion.replace(palabrasAcambiar[i],valores[i]);
}
//resultado: el pan1 es mejor que el pan12
//resultado deseado: el pan1 es mejor que el pan2
I already know that I change the "bread" of the "pan2" for "pan1" and it turned out the "pan12" < - lol
Well .. I wanted to know if anyone knows how to deal with this problem?