Skip to content

Instantly share code, notes, and snippets.

@bashizip
Created January 12, 2015 11:05
Show Gist options
  • Save bashizip/b028b3cc6df8dbb4ad6b to your computer and use it in GitHub Desktop.
Save bashizip/b028b3cc6df8dbb4ad6b to your computer and use it in GitHub Desktop.
Trim text to display preserving whole word at end
String textToDisplay=textToTrim.substring(0,(textToTrim.length() > 120) ? 120 : textToTrim.length());
if (not.getQuestionMessage().lastIndexOf(' ') != textToDisplay.length() &&textToDisplay.length()!=textToTrim().length()) {
textToDisplay = textToDisplay + textToTrim.substring(textToDisplay.length(),textToTrim.indexOf(" ", textToDisplay.length()-1))+ " ...";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment