Java tutorial
//package com.java2s; /* * Copyright ThinkTank Maths Limited 2006 - 2008 * * This file is free software: you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation, either version 3 of the License, or (at your option) * any later version. * * This file is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public License * along with this file. If not, see <http://www.gnu.org/licenses/>. */ import java.util.Vector; public class Main { /** * J2ME implementation of String.split(). Is very fragile. * * @param string * @param separator * @return */ public static String[] stringSplit(String string, char separator) { Vector parts = new Vector(); int start = 0; for (int i = 0; i <= string.length(); i++) { if ((i == string.length()) || (string.charAt(i) == separator)) { if (start == i) { // no data between separators parts.addElement(""); } else { // data between separators String part = string.substring(start, i); parts.addElement(part); } // start of next part is the char after this separator start = i + 1; } } // return as array String[] partsArray = new String[parts.size()]; for (int i = 0; i < partsArray.length; i++) { partsArray[i] = (String) parts.elementAt(i); } return partsArray; } }