Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I limit string length in android?

Tags:

android

suppose I have a string below.

"This is my string blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah"

I only want to show "This is my string" part and cut "blah" part.

So... I want to make my String as "This is my string" and do not want to

show my string as "this is my string blah blah blah blah".

Is there anyway to cut or limit String value in android?

like image 299
Seho Lee Avatar asked Nov 27 '22 00:11

Seho Lee


1 Answers

Substring the string to 50 characters, which returns first 50 characters

You may need to something like this:

 String s = blahString.substring(0,50);

Then set those to your textbox:

yourText.setText(s);
like image 125
kosa Avatar answered Dec 22 '22 20:12

kosa