Java String Break breakString(String string, int l, String newLine)

Here you can find the source of breakString(String string, int l, String newLine)

Description

Breaks a String for showing.

License

Open Source License

Parameter

Parameter Description
string The String.
l The desired long.
newLine The newline char, can be: \n or $lt;br/>

Return

The trimmed URL.

Declaration

public static final String breakString(String string, int l, String newLine) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from www.ja v a 2  s.  c om
     * Breaks a String for showing. Breaking a String its just inserting a new
     * line character inside the text at a specified position, in order for the
     * string to spawn 2 lines instead of just 1 very long line.
     *
     * @param string  The String.
     * @param l       The desired long.
     * @param newLine The newline char, can be: \n or $lt;br/>
     *
     * @return The trimmed URL.
     */
    public static final String breakString(String string, int l, String newLine) {
        int length = (l == 0) ? 80 : l;
        int inserts = string.length() / length;
        StringBuilder b = new StringBuilder(string);

        for (int k = 0; k < inserts; k++) {
            b.insert(length * (k + 1), newLine);
        }

        return b.toString();
    }
}

Related

  1. breakString(String input, int partLength)
  2. breakString(String remainingStr, String soFar, int maxLineLength)
  3. breakString(String str, int maxLineLenght)
  4. breakString(String text, int maxsize)
  5. breakString(String theString)