Here you can find the source of indentString(String s, char open, char middle, char close)
public static String indentString(String s, char open, char middle, char close)
//package com.java2s; //License from project: Open Source License public class Main { /**/*from w ww . j av a 2 s .c o m*/ * To be used with (open,middle,close)=('[',',',']') for the output of ToStringBuilder.reflectionToString */ public static String indentString(String s, char open, char middle, char close) { StringBuilder b = new StringBuilder(); int level = 0; for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); if (c == open) { b.append(c); b.append("\n"); ++level; for (int j = level; j > 0; --j) b.append(" "); } else if (c == close) { b.append("\n"); --level; for (int j = level; j > 0; --j) b.append(" "); b.append(c); } else if (c == middle) { b.append(c); b.append("\n"); for (int j = level; j > 0; --j) b.append(" "); } else { b.append(c); } } return b.toString(); } }