Java tutorial
//package com.java2s; /** * Title: efa - elektronisches Fahrtenbuch fr Ruderer * Copyright: Copyright (c) 2001-2011 by Nicolas Michael * Website: http://efa.nmichael.de/ * License: GNU General Public License v2 * * @author Nicolas Michael * @version 2 */ public class Main { public static String wrapString(String s, int maxchar) { StringBuffer str = new StringBuffer(); while (s.length() > 0) { s = s.trim(); int pos = -1; for (int i = 0; i < s.length() && (i < maxchar || pos < 0); i++) { if (s.charAt(i) == ' ') { pos = i; } } if (pos > 0) { str.append((str.length() > 0 ? "\n" : "") + s.substring(0, pos)); s = s.substring(pos + 1); } else { str.append(s); s = ""; } } return str.toString(); } }