The String#replaceFirst()
method 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 question is how do I make the condition to parse the string and find word to use the methods presented.
Here it deletes the last typed character.
texto = txtTexto.getText().toString();
int length = texto.length();
txtTexto.setText(texto.substring(0, length-1));
Here analyzes the condition to delete 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 works in sin , but when it falls into the other condition it deletes sin and keeps a on the screen, if you reverse the order the condition of the sin function