0
I’m trying to make a return
in the variable to count how many letters there are in the typed word and ignore the typed spaces, but I don’t know how to join the length
with the trim
, says the following message:
Cannot invoke Trim() on the Primitive type int.
public Integer contaCarateresSemEspaços(String texto) {
return texto.length().trim();
}
Just remembering that
\s
will also remove other characters, such as TAB and line breaks (depending on the string and what you need, it may make a difference or not). If you want to remove only the spaces, usereplaceAll(" ", "")
– hkotsubo