Stingクラスを独自に実装するSplitメソッドは、ある文字に基づいて文字列配列に分割します.

1129 ワード

	/**
	 *      
	 * 
	 * @param util
	 *                   
	 * @param split
	 *               
	 * @return
	 */
	public static String[] splitUtil(String util, String split) {
		String splits[] = null;
		Vector vector = new Vector();
		int startIndex = 0;//         
		int index = 0;//           
		startIndex = util.indexOf(split);//           
		//                   ,             -1    
		while (startIndex < util.length() & startIndex != -1) {
			String temp = util.substring(index, startIndex);
			vector.addElement(temp);
			//           
			index = startIndex + split.length();
			//          
			startIndex = util.indexOf(split, startIndex + split.length());

		}
		//       
		vector.addElement(util.substring(index + 1 - split.length()));
		//  VECTOR       
		splits = new String[vector.size()];
		for (int i = 0; i < splits.length; i++) {
			splits[i] = (String) vector.elementAt(i);
		}
		return splits;
	}