Java Utililty Methods String Indent Format

List of utility methods to do String Indent Format

Description

The list of methods to do String Indent Format are organized into topic(s).

Method

StringindentCode(String code, int indentLevel)
Adds indentLevel spaces to every line of code.
StringBuilder sb = new StringBuilder();
for (int i = 0; i < indentLevel; i++) {
    sb.append(' ');
String indent = sb.toString();
sb = new StringBuilder();
String[] lines = code.split("\n");
for (String line : lines) {
...
Stringindented(String indenter, String s)
This method doesn't honor consecutive \n's unless they're separated.
String[] sArr = s.split("\n");
String result = "";
for (String currLine : sArr) {
    result += indenter + currLine + "\n";
return result;
StringindentHtmlSpaces(int count)
Indent with HTML no break spaces.
StringBuilder builder = new StringBuilder();
for (int i = 0; i < count; i++)
    builder.append("&nbsp;");
return builder.toString();
Stringindention(int level, int tabSize)
Create an indention string that contains level * tabSize space characters.
StringBuilder indention = new StringBuilder();
for (int i = 0; i < level * tabSize; i++) {
    indention.append(" ");
return indention.toString();
StringindentLinesAfterNth(final int skip, final int indent, final String str)
indent Lines After Nth
final StringBuilder prefix = new StringBuilder();
for (int i = 0; i < indent; i++) {
    prefix.append(' ');
final StringBuilder out = new StringBuilder();
final String[] lines = str.split("\\n");
int count = 0;
for (String line : lines) {
...
voidindentMultilineValue(String value, StringBuilder tableInfo, int[] columnWidths, boolean printNull)
comment indent processing for multi-line values values should be indented the same amount on each line if the first line comment starts indented by k, the following line comments should also be indented by k
if (value == null) {
    if (printNull) {
        tableInfo.append(String.format("%-" + ALIGNMENT + "s", value));
    tableInfo.append(LINE_DELIM);
} else {
    String[] valueSegments = value.split("\n|\r|\r\n");
    tableInfo.append(String.format("%-" + ALIGNMENT + "s", valueSegments[0])).append(LINE_DELIM);
...
StringindentNextLines(String text, String indent)
indent Next Lines
String origText = new String(text);
String ret = new String();
String[] lines = text.split("\\n");
for (int i = 0; i < lines.length; i++) {
    if (i == lines.length - 1 && !origText.endsWith("\n"))
        ret += indent + lines[i];
    else
        ret += indent + lines[i] + "\n";
...
StringindentParagraph(String textBefore, String textToModify)
Return a paragraph who insert spaces at the beginning of lines.
int indexU = textBefore.lastIndexOf('\n');
return indentParagraph(textToModify, indexU + 1);
StringindentRows(int level, String ss, String indentStr)
indent Rows
StringBuilder sb = new StringBuilder();
for (int ii = 0; ii < level; ii++) {
    sb.append(indentStr);
ss = ss.replaceAll("(\r\n|\r|\n)", "\r\n");
ss = "\r\n" + ss;
String repl = "\r\n" + sb.toString();
ss = ss.replace("\r\n", repl);
...
StringindentStr(int level)
indent Str
if (level < XMLIndent.length) {
    return XMLIndent[level];
} else {
    return XMLIndent[XMLIndent.length - 1] + indentStr(level + 1 - XMLIndent.length);