4
The method String#replaceFirst()
is used to replace the first occurrence of a substring in a string, but how should I proceed if I want to do this with the last occurrence?
The doubt is as follows how I will make the condition to analyze the string and if you find word use the methods shown.
Here deletes last character typed.
texto = txtTexto.getText().toString();
int length = texto.length();
txtTexto.setText(texto.substring(0, length-1));
Here analyzes condition to erase an entire word.
if (texto.substring(length-3, length).equals("sin")){
txtTexto.setText(replaceLast(texto, "sin", ""));
}
else if if (texto.substring(length-4, length).equals("asin")){
txtTexto.setText(replaceLast(texto, "asin", ""));
}
This way it works in the sin, but when it falls into the other condition eliminates the sin and maintains the to on the screen, if you reverse the order the condition of the sin works the Asin so smaller characters, type 2 characters do not work.
http://answall.com/help/mcve
– Maniero