I have a method that takes text as a parameter and makes a .split
in the text separating the words with " "
. For each word in the text I do a check checking if the word is equal to the item in my list of Enum
, if the word is equal to Enum
the word is formatted for css. Since I separate words by " "
, some words may come precedent or come with a .
(period). I would like to treat only the word by ignoring the point and after treating the word, to return the point to its place, how can I do? I thought of some situations but to no avail. This is my method:
public static String checkTipoPokemon(String texto) {
List<TipoPokemon> lista = Arrays.asList(TipoPokemon.values());
String palavras[] = texto.split(" ");
String tipoIngles = null;
for (int i = 0; i < lista.size(); i++) {
String tipo = lista.get(i).name().toUpperCase();
tipoIngles = tipo + "-type";
for (String palavra : palavras) {
if (palavra.toUpperCase().equals(tipo) || palavra.toUpperCase().equals(tipoIngles.toUpperCase())) {
texto = texto.replace(palavra,
"<span id=" + "tipo-" + tipo.toLowerCase() + ">" + palavra + "</span>");
}
}
}
return texto;
}
Ex: Note the following text:
electic. When the HP is below 1/3, FIRE moves win a bonus of 50% grass.
There are 3 words to format: electric , fire and grass . However electric has a point before it and grass has the point afterwards. You should ignore the dots and just format the word thus getting at the end:
.<span id="tipo-electric">electric</span>
<span id="tipo-grass">grass</span>.
Depending on the word, it will have a different formatting, but the words will have similar formatting, eg:
.tipo-pokemon span {
text-transform: uppercase;
font-weight: bold;
font-style: italic;
}
.tipo-pokemon span#fire {
color: #EE8130;
}
.tipo-pokemon span#water {
color: #6890F0;
}
.tipo-pokemon span#ice {
color: #98D8D8;
}
.tipo-pokemon span#electric {
color: #F8D030;
}
.tipo-pokemon span#grass {
color: #78C850;
}
.tipo-pokemon span#dark {
color: #705848;
}
.tipo-pokemon span#bug {
color: #A8B820;
}
.tipo-pokemon span#ghost {
color: #705898;
}
.tipo-pokemon span#rock {
color: #B8A038;
}
.tipo-pokemon span#fairy {
color: #EE99AC;
}
.tipo-pokemon span#ground {
color: #E2BF65;
}
.tipo-pokemon span#dragon {
color: #7038F8;
}
.tipo-pokemon span#psychic {
color: #F85888;
}
.tipo-pokemon span#poison {
color: #A040A0;
}
.tipo-pokemon span#normal {
color: #A8A878;
}
.tipo-pokemon span#fighting {
color: #C03028;
}
.tipo-pokemon span#steel {
color: #B8B8D0;
}
.tipo-pokemon span#flying {
color: #A890F0;
}
Following @Sorack's suggestion, follow the print of how my dataTable:
Thetextgeneratedinthefirstcolumnwasthis:
<spanclass="tipo-pokemon <span class="tipo-pokemon grass">grass</span>"><span class="tipo-pokemon grass">grass</span></span> <span class="tipo-pokemon <span class="tipo-pokemon electric">electric</span>"><span class="tipo-pokemon electric">electric</span></span>. Quando o HP está abaixo de 1/3, os moves do tipo <span class="tipo-pokemon <span class="tipo-pokemon fire">fire</span>"><span class="tipo-pokemon fire">FIRE</span></span> ganham um bônus de 50% grass