1
I am using this method to delete the last character typed in a Textview:
texto = txtTexto.getText().toString();
int length = texto.length();
txtTexto.setText(texto.substring(0, length - 1));
When a word like sine I want to erase her whole.
1
I am using this method to delete the last character typed in a Textview:
texto = txtTexto.getText().toString();
int length = texto.length();
txtTexto.setText(texto.substring(0, length - 1));
When a word like sine I want to erase her whole.
1
The method can be used String#replace()
to eliminate her.
But if you do:
texto = txtTexto.getText().toString();
texto.replace("seno", "");
The above code will not work as expected, it will not modify the calling object because strings (or better, variables) in Java are immutable, then what you need to do is assign the result to a new string or for the same variable as:
texto = txtTexto.getText().toString();
texto = texto.replace("seno", "");
Other similar functions that may be useful to you:
String#replaceFirst()
: Replaces the first occurrence of a word in a text.String#replaceAll()
: Does the same thing as function String#replace()
, but this accepts the use of regular expressions.`String#replaceFirst() occurs in the first and to replace the last occurrence of a word in text.
1
Use the replace
:
texto.replace("seno","")
Browser other questions tagged java android
You are not signed in. Login or sign up in order to post.
But you want to delete it wherever it appears, or only if it appears at the end of the string?
– mgibsonbr