Here you can find the source of splitWithEscapeChar(String s, char delimiter, char escape)
public static List<String> splitWithEscapeChar(String s, char delimiter, char escape)
//package com.java2s; /*/*from ww w .j a va2 s . co m*/ * All GTAS code is Copyright 2016, Unisys Corporation. * * Please see LICENSE.txt for details. */ import java.util.ArrayList; import java.util.List; public class Main { /** * Split a string 's' using 'delimiter' but don't split on any delimiters * escaped with 'escape' character. For example, if we call this method * with s = "mc?'foo'bar", delimiter = '\'', escape = '?' the method * should return ["mc'foo", "bar"]. Note as a side-effect, the escape * characters are removed from the final output. */ public static List<String> splitWithEscapeChar(String s, char delimiter, char escape) { String escapedDelimiter = String.format("\\%c\\%c", escape, delimiter); final String sentinel = "~XYZ~"; String tmp = s.replaceAll(escapedDelimiter, sentinel); String regex = String.format("\\%c", delimiter); String[] tmpSplit = tmp.split(regex); List<String> rv = new ArrayList<>(tmpSplit.length); for (String myString : tmpSplit) { rv.add(myString.replaceAll(sentinel, "\\" + delimiter).trim()); } return rv; } }