Atlas91
Atlas91

Reputation: 5904

Take last word in textview

I tryed to take the last word displayed in a textview but not works with my way. i tryed in this way:

String test =  ((TextView)selectedContact).getText().toString().split(" ")[0];

But it takes always all words.

Upvotes: 0

Views: 579

Answers (2)

nKn
nKn

Reputation: 13761

In one line:

String last = test.substring(test.lastIndexOf(" ") + 1);

This will take the substring from the last space to the end of your String, which is what you're looking for.

Upvotes: 1

Fahriyal Afif
Fahriyal Afif

Reputation: 558

String a[] = tv.getText().toString().split(" ");
String last_text = a[a.length-1];

Upvotes: 2

Related Questions