Split a String at the first occurrence of the delimiter. Does not include the delimiter in the result. @param toSplit the string to split @param delimiter to split the string up with @return a two element array with index 0 being before the delimiter, and index 1 being after the delimiter
(String toSplit, String delimiter)
| 309 | * or <code>null</code> if the delimiter wasn't found in the given input String |
| 310 | */ |
| 311 | public static String[] split(String toSplit, String delimiter) { |
| 312 | if (!hasLength(toSplit) || !hasLength(delimiter)) { |
| 313 | return null; |
| 314 | } |
| 315 | int offset = toSplit.indexOf(delimiter); |
| 316 | if (offset < 0) { |
| 317 | return null; |
| 318 | } |
| 319 | String beforeDelimiter = toSplit.substring(0, offset); |
| 320 | String afterDelimiter = toSplit.substring(offset + delimiter.length()); |
| 321 | return new String[]{beforeDelimiter, afterDelimiter}; |
| 322 | } |
| 323 | |
| 324 | /** |
| 325 | * Tokenize the given String into a String array via a StringTokenizer. |