Display specific length string without truncating word in Java


If you want to display substring of text and don’t want to truncate word in a substring, then you can use below method to fulfill your requirement.

public static String textSubString(String text, int start, int end){

String str="";
int limit=0;
limit=end;

if(text.length()!=0 && text!=""){

String substr=text.substring(end,end+1);

if(substr!=""){

while(!substr.equals("")){
substr=text.substring(limit,++limit);
substr=substr.trim();
}
}
str=text.substring(start,limit);
}
return str;
}

Related Posts: