How do I delete a word at a time?

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));

    

asked by anonymous 08.03.2015 / 14:15

2 answers

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:

08.03.2015 / 15:06
1

Use replace :

texto.replace("seno","")
    
08.03.2015 / 14:21