Shoaib Quraishi
Shoaib Quraishi

Reputation: 21

Extract Text From EditText and Print in TextView

I have a question:

I have entered a text in EditText, 'My Name is Khan'

I just want to print just 'Khan' in TextView (not 'My Name is Khan', just 'Khan' I want in TextView).

How to do it?

Upvotes: 2

Views: 193

Answers (1)

Sujith Niraikulathan
Sujith Niraikulathan

Reputation: 2141

Parse your string using split.

String[] s = edittext.getText.toString().split(Pattern.quote(" "));

Then get the last word.

String name = s[s.length-1];

Now set it

textView.setText(name);

Upvotes: 5

Related Questions