Java String Indent Format indent(int i, String s)

Here you can find the source of indent(int i, String s)

Description

indent

License

Open Source License

Declaration

public static String indent(int i, String s) 

Method Source Code

//package com.java2s;
/*//from   ww w  . j  av a2 s .  co m
(C) 2007 Stefan Reich (jazz@drjava.de)
This source file is part of Project Prophecy.
For up-to-date information, see http://www.drjava.de/prophecy
    
This source file is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation, version 2.1.
*/

public class Main {
    public static String indent(int i, String s) {
        String spaces = repeat(i, ' ');
        return spaces + s.replace("\n", "\n" + spaces);
    }

    private static String repeat(int len, char c) {
        char[] chars = new char[len];
        for (int i = 0; i < len; i++)
            chars[i] = c;
        return new String(chars);
    }

    public static String replace(String pattern, String substitute, String s) {
        StringBuffer buf = new StringBuffer();
        while (true) {
            int i = s.indexOf(pattern);
            if (i >= 0) {
                buf.append(s.substring(0, i));
                buf.append(substitute);
                s = s.substring(i + pattern.length());
            } else {
                buf.append(s);
                break;
            }
        }
        return buf.toString();
    }
}

Related

  1. indent(final StringBuilder aSb, final String aIndentString)
  2. indent(final StringBuilder buf, int level)
  3. indent(final StringBuilder s, final int depth)
  4. indent(final StringBuilder sb, final int indent)
  5. indent(int count)
  6. indent(int indent)
  7. indent(int indent)
  8. indent(int indent)
  9. indent(int indent)