Java tutorial
//package com.java2s; //License from project: Apache License public class Main { public static String shortenText(final String content, final int length) { String result = content.substring(0, length); if (content.charAt(length) != ' ') result = result.substring(0, result.lastIndexOf(" ")); return result; } }