HaOx
HaOx

Reputation: 1879

Copy Only Some Characters From TextView

Is there any function in Android that allows me to copy only some characters from a TextView?

For example, if the TextView = "This is Good", how can I get only the string "Good"?

Upvotes: 0

Views: 233

Answers (2)

Richard Lewin
Richard Lewin

Reputation: 1870

I am pretty sure there is not "the one function" you are looking for. Instead the following will do what you want.

Get the text:

 String text = textview.getText().toString();

Then, with regard to getting "Good" in your sentence example, use the String.substring() function it:

String innerString = text.substring(8);

The substring above is for all characters from the 8th index onwards. A range can be specified instead if needed such as:

String innerString = text.substring(8, 10);

That will start from the 8th character and go up to (but not including) the 10th character.

Upvotes: 2

AAnkit
AAnkit

Reputation: 27549

try StringBuilder class. firt create StringBuilder object.

  StringBuilder sb=new StringBuilder(textview.gettext());

check methods available in this class link for the class

Upvotes: 1

Related Questions