Here you can find the source of truncateSentence(String input, int length)
public static String truncateSentence(String input, int length)
//package com.java2s; //License from project: Apache License public class Main { public static String truncateSentence(String input, int length) { int length2 = length; while (length2 > 0) { char c = (input.charAt(length)); if (c < 'A' || c > 'z') { length2 = 0;/*from w w w.j a v a 2s.c om*/ } else { length--; length2--; } } return input.substring(0, length); } }