4
I have a method that takes a text as a parameter and makes a .split
in the text separating the words by " "
. For each word in the text I make a check to see if the word is equal to the item in my list of Enum
, if the word is equal to Enum
the word takes a format for css. How do I separate the words by " "
some words may come precedent or proceeding with a .
(point). I would like to treat only the word by ignoring the point and after treating the word, return the point to its place, how can I do ? I thought of some situations but without success. 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 HP is below 1/3, FIRE type moves win a bonus of 50% Rass.
There are 3 words to be formatted: Electric, fire and Grass. However Electric has a point before and Grass has the point after. One should ignore the points and format only 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, e.g.:
.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;
}
At @Sorack’s suggestion, follow the print of how my datatable looked:
The text generated in the first column was this:
<span class="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
You can add an example of these separate words with space and containing the dot?
– user28595