List of utility methods to do String Split
int[] | splitInts(String str) Parse comma-separated list of ints and return as array. StringTokenizer tokenizer = new StringTokenizer(str, ","); int n = tokenizer.countTokens(); int[] list = new int[n]; for (int i = 0; i < n; i++) { String token = tokenizer.nextToken(); list[i] = Integer.parseInt(token); return list; ... |
String[] | splitLast(String target, String pattern) split Last int index = target.lastIndexOf(pattern); if (index == -1) { throw new RuntimeException("Pattern is not found."); return new String[] { target.substring(0, index), target.substring(index + 1) }; |
String[] | splitSteps(String str, String split) split Steps return str.split(split);
|
String[] | splitString(String tokenedStr, String token) split String String[] ids = null; if (tokenedStr != null) { StringTokenizer st = new StringTokenizer(tokenedStr, token); final int arraySize = st.countTokens(); if (arraySize > 0) { ids = new String[arraySize]; int counter = 0; while (st.hasMoreTokens()) { ... |
String[] | explode(String original, String split) explode if (original == null || original.length() == 0 || split == null || split.length() == 0) { return new String[] { original }; ArrayList<String> strs = new ArrayList<String>(); int index = 0; int len = split.length(); while ((index = original.indexOf(split)) != -1) { ... |
String | getFirstWord(String str) get First Word return str.split(SPACE)[0];
|
String | getLine(String text, int line) get Line int tempPos, tempStart, tempEnd; for (int pos = 0; pos <= text.length();) { tempStart = pos; tempPos = text.indexOf("\n", pos); if (tempPos == -1) { tempEnd = text.length(); pos = tempEnd + 1; } else { ... |
List | stringToLongArray(String src, String separator) string To Long Array List<Integer> res = new ArrayList<Integer>(); if (src != null && separator != null) { try { String[] strArray = src.split(separator); if (strArray.length > 0) { for (int i = 0; i < strArray.length; i++) { res.add(Integer.parseInt(strArray[i])); } catch (Exception e) { return res; |
String[] | strToArray(String string) Convert String to Array of Strings using default delimiter (",") return strToArray(string, DEFAULT_DELIM);
|
String[] | strToArray(String string, String delim) Convert String to Array of Strings if (TextUtils.isEmpty(delim)) { throw new IllegalArgumentException("delim cannot be empty"); if (string == null) { return null; if (string.length() == 0) { return new String[] {}; ... |