Here you can find the source of indent(String value, int spaces)
Parameter | Description |
---|---|
value | The string whose lines are to be indented |
spaces | The number of spaces by which to indent each line |
public static String indent(String value, int spaces)
//package com.java2s; //License from project: Open Source License public class Main { /**/*from w w w. j a v a 2s . c o m*/ * Indents all lines of the argument string by the specified number of spaces. * @param value The string whose lines are to be indented * @param spaces The number of spaces by which to indent each line * @return The resulting indented string. Each line will be terminated by * a single newline character, regardless of the line terminators * used in the original string. */ public static String indent(String value, int spaces) { if (spaces < 0) spaces = 0; String indent = ""; for (int i = 0; i < spaces; i++) { indent += " "; } String[] lines = value.split("\r\n|\r|\n"); String output = ""; for (int i = 0; i < lines.length; i++) { output += indent + lines[i] + "\n"; } return output; } }