( begin auto-generated from split.xml ) The split() function breaks a string into pieces using a character or string as the divider. The delim parameter specifies the character or characters that mark the boundaries between each piece. A String[] array is returned that contains each of the p
(String value, char delim)
| 9194 | * @param delim the character or String used to separate the data |
| 9195 | */ |
| 9196 | static public String[] split(String value, char delim) { |
| 9197 | // do this so that the exception occurs inside the user's |
| 9198 | // program, rather than appearing to be a bug inside split() |
| 9199 | if (value == null) return null; |
| 9200 | //return split(what, String.valueOf(delim)); // huh |
| 9201 | |
| 9202 | char chars[] = value.toCharArray(); |
| 9203 | int splitCount = 0; //1; |
| 9204 | for (int i = 0; i < chars.length; i++) { |
| 9205 | if (chars[i] == delim) splitCount++; |
| 9206 | } |
| 9207 | // make sure that there is something in the input string |
| 9208 | //if (chars.length > 0) { |
| 9209 | // if the last char is a delimeter, get rid of it.. |
| 9210 | //if (chars[chars.length-1] == delim) splitCount--; |
| 9211 | // on second thought, i don't agree with this, will disable |
| 9212 | //} |
| 9213 | if (splitCount == 0) { |
| 9214 | String splits[] = new String[1]; |
| 9215 | splits[0] = value; |
| 9216 | return splits; |
| 9217 | } |
| 9218 | //int pieceCount = splitCount + 1; |
| 9219 | String splits[] = new String[splitCount + 1]; |
| 9220 | int splitIndex = 0; |
| 9221 | int startIndex = 0; |
| 9222 | for (int i = 0; i < chars.length; i++) { |
| 9223 | if (chars[i] == delim) { |
| 9224 | splits[splitIndex++] = |
| 9225 | new String(chars, startIndex, i-startIndex); |
| 9226 | startIndex = i + 1; |
| 9227 | } |
| 9228 | } |
| 9229 | //if (startIndex != chars.length) { |
| 9230 | splits[splitIndex] = |
| 9231 | new String(chars, startIndex, chars.length-startIndex); |
| 9232 | //} |
| 9233 | return splits; |
| 9234 | } |
| 9235 | |
| 9236 | |
| 9237 | static public String[] split(String value, String delim) { |