Open top menu



In this blog explain how to get Substring from String in android..

String str  = "1234567890" ;
String Char  =  "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

for example...

Step first - get string legth
...................................................................................................................................................................

//get length
int lenth=Char.length();

// you get last string
String Lastchar=Char.substring(Char.length()-1); //same as  str
Log.e("Lastchar...",Lastchar);
.................................................................................................................................................................


Step 2- get Substring
...................................................................................................................................................................

// you get last string 
String substr=Char.substring(0,3); //same as  str
Log.e("substring...",substr);

output:- substr - ABC;
...................................................................................................................................................................


Step 2- How to remove space
...................................................................................................................................................................
 String str = the good boy

// you get last string 
String substr=str.substring(0,4).trim(); //same as  str

Log.e("substring...",substr);

output:- substr- the;
Tagged

0 comments