src/java/org/pifan/util/StringUtils.java
/**
     * Format the given string by inserting the given text every maxLineLength
     * characters.
     * 
     * @param stringToFormat
     *            The string to format
     * @param stringToInsert
     *            The string to insert every maxLineLength characters
     * @param maxLineLength
     * @return The formatted string
     */
Format the given string by inserting the given text every maxLineLength
characters.

@param stringToFormat
The string to format
@param stringToInsert
The string to insert every maxLineLength characters
@param maxLineLength
@return The formatted string
Format the given string by inserting the given text every maxLineLength characters . @param stringToFormat The string to format @param stringToInsert The string to insert every maxLineLength characters @param maxLineLength @return The formatted string
public static final String wrapToLength(String stringToFormat, String stringToInsert, int maxLineLength) {
        if (stringToFormat == null) {
            return "";
        }
        final StringBuilder currentText = new StringBuilder(stringToFormat);
        final StringBuilder formattedText = new StringBuilder();
        for (int i = 0, counter = 0; i < currentText.length(); i++, counter++) {
            if (counter == maxLineLength) {
                int nextSpace = StringUtils.findNextSpace(currentText.substring(i));
                if (nextSpace >= 0) {
                    formattedText.append(currentText.substring(i, i + nextSpace));
                    formattedText.append(stringToInsert);
                    i = i + nextSpace;
                    counter = 0;
                } else {
                    formattedText.append(currentText.substring(i));
                    formattedText.append(stringToInsert);
                    i = i + currentText.substring(i).length();
                    counter = 0;
                }
            } else {
                formattedText.append(currentText.charAt(i));
            }
        }
        return formattedText.toString();
    }
public static final String wrapToLength ( String stringToFormat , String stringToInsert , int maxLineLength ) { if ( stringToFormat == null ) { return "" ; } final StringBuilder currentText = new StringBuilder ( stringToFormat ) ; final StringBuilder formattedText = new StringBuilder ( ) ; for ( int i = 0 , counter = 0 ; i < currentText . length ( ) ; i ++ , counter ++ ) { if ( counter == maxLineLength ) { int nextSpace = StringUtils . findNextSpace ( currentText . substring ( i ) ) ; if ( nextSpace >= 0 ) { formattedText . append ( currentText . substring ( i , i + nextSpace ) ) ; formattedText . append ( stringToInsert ) ; i = i + nextSpace ; counter = 0 ; } else { formattedText . append ( currentText . substring ( i ) ) ; formattedText . append ( stringToInsert ) ; i = i + currentText . substring ( i ) . length ( ) ; counter = 0 ; } } else { formattedText . append ( currentText . charAt ( i ) ) ; } } return formattedText . toString ( ) ; }
Format the given string by inserting the given text every maxLineLength
 characters.
Format the given string by inserting the given text every maxLineLength characters .
// look for the next space to insert the necessary text
 // a space was found
 // a space couldn't be found...simply add all of the text
