List of utility methods to do String Split by Quote
List | quoteAwareSplit(String str, char delim) Break str into individual elements, splitting on delim (not in quotes). boolean inQuotes = false; boolean inEscape = false; List<String> elements = new ArrayList<>(); StringBuilder buffer = new StringBuilder(); for (char c : str.toCharArray()) { if (c == delim && !inQuotes) { elements.add(buffer.toString()); buffer.setLength(0); ... |
String[] | split(String sString, boolean bIgnoreQuotes) This is a simple utility to split strings. List vRes = new ArrayList(); char splitChar = ' '; char[] vChars = sString.trim().toCharArray(); StringBuffer sbCurrentToken = new StringBuffer(); for (int i = 0; i < vChars.length; i++) { if (vChars[i] == splitChar) { if (sbCurrentToken.toString().length() != 0) { vRes.add(sbCurrentToken.toString()); ... |
String[] | split(String str, char chrSplit, char chrQuote)split divides a string into many strings based on a delimiter The main difference between this split and the one that comes with Java is this one will ignore delimiters that are within quoted fields NOTE: Delimiter will be ignored once chrQuote is encountered. List<String> tokens = new ArrayList<String>(); String str1 = new String(); boolean inQuote = false; for (int i = 0; i < str.length(); i++) { if (str.charAt(i) == chrSplit && !inQuote) { tokens.add(str1); str1 = new String(); } else if (str.charAt(i) == chrQuote) { ... |
List | splitArrayStringQuoted(String array, char quoteChar) Takes a string and splits it according to the quote character '. Use this method for splitting a string into several parts, where each part corresponds to a quoted substring in the input. A string "['stringA' 'stringB']" will result in the list (stringA,stringB) with ' being the character used for qouting. array = array.replace("[", ""); array = array.replace("]", ""); List<String> result = new ArrayList<>(); Integer actStart = null; for (int i = 0; i < array.length(); i++) { if (array.charAt(i) == quoteChar) { if (actStart == null) { if (i < array.length() - 1) { ... |
List | splitHandleQuotes(String s) split Handle Quotes ArrayList<String> results = new ArrayList<String>(); char delimiter = ','; char quoteChar = '"'; char escapeChar = '\\'; StringBuffer current = new StringBuffer(""); boolean inQuotation = false; boolean escaping = false; for (int i = 0; i < s.length(); ++i) { ... |
String[] | splitIgnoringQuotes(String str, char separatorChar) split Ignoring Quotes if (str == null) { return null; int len = str.length(); if (len == 0) { return EMPTY_STRING_ARRAY; List<String> list = new ArrayList<String>(); ... |
String[] | splitIgoringQuotes(String str) Split method will split the given string to substrings every time it finds the space character (' '). ArrayList<String> strings = new ArrayList<String>(5); StringBuilder sb = new StringBuilder(); str = str.trim(); try { for (int i = 0; i < str.length(); i++) { while (str.charAt(i) == ' ') i++; if (str.charAt(i) == '"') { ... |
String[] | splitOnCharWithQuoting(String s, char splitChar, char quoteChar, char escapeChar) This function splits the String s into multiple Strings using the splitChar. List<String> result = new ArrayList<String>(); int i = 0; int length = s.length(); StringBuilder b = new StringBuilder(); while (i < length) { char curr = s.charAt(i); if (curr == splitChar) { if (b.length() > 0) { ... |
String[] | splitOnCharWithQuoting(String s, char splitChar, char quoteChar, char escapeChar) This function splits the String s into multiple Strings using the splitChar. List<String> result = new ArrayList<>(); int i = 0; int length = s.length(); StringBuilder b = new StringBuilder(); while (i < length) { char curr = s.charAt(i); if (curr == splitChar) { if (b.length() > 0) { ... |
String[] | splitOptions(String quotedOptionString) Split up a string containing options into an array of strings, one for each option. List<String> result; StringBuilder str; int i; String optStr; result = new ArrayList<>(); str = new StringBuilder(quotedOptionString); while (true) { i = 0; ... |