1
I want to standardize what the user typed in edittext by capitalizing the first letter of each word and the rest lower case. How do I do this?
The part that arrow the variables in the model class
Contato c = new Contato();
c.setNome(etNome.getText().toString());
This worked by changing the first letter of the first word, I would like you to do it with all words, could help?
– Costamilam
@Guilhermecostamilam words separated by a space?
– user28595
infrequently this
– Costamilam
@Guilhermecostamilam see the edition.
– user28595
out of curiosity what is the s in the split?
– Costamilam
@Guilhermecostamilam split breaks the string into an array of other strings based on a separator that you pass as parameter. In this case, I use
\\swhich is the representation of space in regex, but you can change tosplit(" ");that works normally.– user28595
Thanks when I use general mind split with the same space I didn’t know I could also use /s but does it make any difference? which one is better?
– Costamilam
@Guilhermecostamilam the literal representation is more recommended, ie it is better to use so
split(" "), although in this case there is no difference in performance.– user28595
For this case it is more interesting to use Stringbuilder. xD
– viana
@acklay altered, thanks for the tip :)
– user28595
I put a clause
ifthere in the middle just not to get an additional space at the end of the stringstrunnecessarily– Costamilam