Java tutorial
//package com.java2s; public class Main { public static String getStringPreview(String str) { String preview; if (str.length() < 29) { preview = str.replace("\n", " "); } else { preview = str.replace("\n", " ").substring(0, 29) + "..."; } return preview; } }