I'm using this method to delete the last character entered in a TextView:
texto = txtTexto.getText().toString();
int length = texto.length();
txtTexto.setText(texto.substring(0, length - 1));
I'm using this method to delete the last character entered in a TextView:
texto = txtTexto.getText().toString();
int length = texto.length();
txtTexto.setText(texto.substring(0, length - 1));
You can use the String#replace()
to delete it.
But if you do:
texto = txtTexto.getText().toString();
texto.replace("seno", "");
The above code will not work as expected, this will not modify the calling object because strings (or rather, variables ) in Java are usable , then what you need to do is assign the result to a new string or to the same variable so :
texto = txtTexto.getText().toString();
texto = texto.replace("seno", "");
Other similar functions that may come in handy to you:
String#replaceFirst()
: Replaces the first occurrence of a word in a text. String#replaceAll()
: Does the same thing as the String#replace()
", but this accepts the use of regular expressions. Use replace
:
texto.replace("seno","")