List of utility methods to do String Split by Delimiter
String[] | split(String value, char delimiter) Splits a string in parts, given a specified delimiter. if (value == null) return null; ArrayList<String> result = new ArrayList<>(); int start = 0; for (int i = 0; i < value.length(); i++) { if (value.charAt(i) == delimiter) { result.add(value.substring(start, i)); start = i + 1; ... |
String[] | split(String value, String delimiter) Splits the given String around the matches defined by the given delimiter into an array. int lastIndex = 0; ArrayList strings = null; int currentIndex = 0; while ((currentIndex = value.indexOf(delimiter, lastIndex)) != -1) { if (strings == null) { strings = new ArrayList(); strings.add(value.substring(lastIndex, currentIndex)); ... |
List | split(String value, String delimiter) Splits a delimiter separated string, tolerating presence of non separator commas within double quoted segments. List<String> result = new ArrayList<String>(); if (value != null) { String[] packages = value.split(delimiter); for (int i = 0; i < packages.length;) { String tmp = packages[i++].trim(); while (count(tmp, "\"") % 2 != 0) { if (i < packages.length) tmp = tmp + delimiter + packages[i++].trim(); ... |
String[] | split(String value, String[] delimiters) Splits a string into substrings using a delimiter array. ArrayList result = new ArrayList(); int firstIndex = 0; int separator = 0; while (firstIndex != -1) { firstIndex = -1; for (int i = 0; i < delimiters.length; i++) { int index = value.indexOf(delimiters[i]); if (index != -1 && (index < firstIndex || firstIndex == -1)) { ... |
String[] | split(String what, char delim) Split a string into pieces along a specific character. if (what == null) return null; char chars[] = what.toCharArray(); int splitCount = 0; for (int i = 0; i < chars.length; i++) { if (chars[i] == delim) splitCount++; if (splitCount == 0) { String splits[] = new String[1]; splits[0] = new String(what); return splits; String splits[] = new String[splitCount + 1]; int splitIndex = 0; int startIndex = 0; for (int i = 0; i < chars.length; i++) { if (chars[i] == delim) { splits[splitIndex++] = new String(chars, startIndex, i - startIndex); startIndex = i + 1; splits[splitIndex] = new String(chars, startIndex, chars.length - startIndex); return splits; |
List | split(String[] srcArray, String delimiterRegExp) split List<String> tokens = null; if (srcArray != null) { tokens = new ArrayList<String>(); for (int i = 0; i < srcArray.length; i++) { if (srcArray[i] == null) { tokens.add(null); } else { String[] currentTokensArray = srcArray[i].split(delimiterRegExp); ... |
String[] | split2(String string, String delimiter) Splits the string by the given delimiter but does not accept delimiters or blank elements and trims all elements. String[] result = split(string, delimiter); ArrayList result2 = new ArrayList(); for (int i = 0; i < result.length; i++) { String mean = result[i].trim(); if (mean.length() > 0 && !mean.equals(delimiter.trim())) { result2.add(mean); return (String[]) result2.toArray(new String[result2.size()]); |
List | splitAll(String str, String delim) Splits a String on a delimiter into a List of Strings. List splitList = null; if (str == null) return splitList; splitList = new ArrayList(); str = str + delim; while (str.indexOf(delim) >= 0) { String strValue = str.substring(0, str.indexOf(delim)); splitList.add(strValue); ... |
String[] | splitAndTrim(String string, String delim) Like org.mule.util.StringUtils#split(String,String) , but additionally trims whitespace from the result tokens. if (string == null) { return null; if (isEmpty(string)) { return new String[] {}; String[] rawTokens = string.split(delim); List<String> tokens = new ArrayList<String>(); ... |
String[] | SplitAt(String s, String delimiter) Split At if (delimiter == null || delimiter.length() == 0) throw new IllegalArgumentException(); if (s == null || s.length() == 0) return new String[] { "" }; int index = 0; boolean first = true; ArrayList<String> strings = null; int delimLength = delimiter.length(); ... |