Here you can find the source of implode(char delimiter, char escape, String... input)
Parameter | Description |
---|---|
input | a parameter |
delimiter | a parameter |
escape | a parameter |
public static String implode(char delimiter, char escape, String... input)
//package com.java2s; // This package is part of the Spiralcraft project and is licensed under public class Main { /**// w w w. j av a 2 s. com * Combine multiple Strings into one using the specified delimiter and * the specified escape character. Occurrences of the delimiter and * the escape character in the individual components will be escaped * by prepending the escape character. * * @param input * @param delimiter * @param escape * @return */ public static String implode(char delimiter, char escape, String... input) { // ClassLog log=ClassLog.getInstance(StringUtil.class); boolean first = true; StringBuilder result = new StringBuilder(); //log.fine("Imploding '"+delimiter+"','"+escape+"',"+ArrayUtil.format(input,"|",null)); for (String str : input) { if (!first) { result.append(delimiter); } else { first = false; } result.append(escape(str, escape, Character.toString(delimiter))); } return result.toString(); } /** * Escapes charsToEscape by preceeding them with the escape char. The * escapeChar is automatically escaped. * * @param input * @param escapeChar * @param charsToEscape * @return */ public static String escape(String input, char escapeChar, String charsToEscape) { if (input == null) { return null; } final StringBuilder out = new StringBuilder(); for (char c : input.toCharArray()) { if (charsToEscape.indexOf(c) > -1 || c == escapeChar) { out.append(escapeChar); } out.append(c); } return out.toString(); } }