Java String Indent Format indent(final StringBuilder aSb, final String aIndentString)

Here you can find the source of indent(final StringBuilder aSb, final String aIndentString)

Description

Changes the indentation of the string, a requested string is appended after every EOFs in the string.

License

Open Source License

Parameter

Parameter Description
aSb [in/out] the string to modify
aIndentString [in] the requested string to append

Declaration

public static void indent(final StringBuilder aSb, final String aIndentString) 

Method Source Code

//package com.java2s;
/******************************************************************************
 * Copyright (c) 2000-2018 Ericsson Telecom AB
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
 *
 * Contributors:/*  w w w  . j  a v  a  2s.  c o m*/
 *   Balasko, Jeno
 *   Lovassy, Arpad
 *
 ******************************************************************************/

public class Main {
    /**
     * Changes the indentation of the string, a requested string is appended after every EOFs in the string. 
     * @param aSb [in/out] the string to modify
     * @param aIndentString [in] the requested string to append
     */
    public static void indent(final StringBuilder aSb, final String aIndentString) {
        replaceString(aSb, "\n", "\n" + aIndentString);
    }

    /**
     * Replaces all the occurrences of a given string
     * @param aSb [in/out] the string to modify 
     * @param aFrom [in] the string to replace
     * @param aTo [in] the replacement string
     */
    public static void replaceString(final StringBuilder aSb, final String aFrom, final String aTo) {
        int index = aSb.indexOf(aFrom);
        while (index != -1) {
            aSb.replace(index, index + aFrom.length(), aTo);
            index += aTo.length(); // Move to the end of the replacement
            index = aSb.indexOf(aFrom, index);
        }
    }
}

Related

  1. indent(final int indents)
  2. indent(final int size)
  3. indent(final String s)
  4. indent(final String string, final String separator)
  5. indent(final StringBuffer buffer, final String text, final int indent)
  6. indent(final StringBuilder buf, int level)
  7. indent(final StringBuilder s, final int depth)
  8. indent(final StringBuilder sb, final int indent)
  9. indent(int count)