J 2 MEプラットフォーム上の文字列の切断方法split()

2115 ワード

なぜJ 2 ME上の文字列処理方法にsplit()という方法がないのか分からない.
文字列のカットをするときに面倒なことがあります.以前先生が教えてくれたmySplitの方法はsplit()の方法と似ています.私は怠け者で直接copyを書きました.

/**
	 *      
	 * 
	 * @param str
	 *                   
	 * @param chr
	 * @return
	 */
	public static String[] mySplict(String str, char chr) {
		/**
		 *       
		 */
		String[] data = null;
		try {
			// a|b|C|d
			// vector    , System.arraycopy   vector;   System.arraycopy        
			//      chr   
			Vector vector = new Vector();
			for (int i = 0; i < str.length(); i++) {
				char c = str.charAt(i);
				if (chr == c) {
					// i      
					vector.addElement(new Integer(i));
				}
			}

			//             
			if (vector.size() == 0) {
				data = new String[] { str };
			}

			if (vector.size() >= 1) {
				data = new String[vector.size() + 1];
			}
			for (int i = 0; i < vector.size(); i++) {
				/**
				 *   
				 */
				int index = ((Integer) vector.elementAt(i)).intValue();
				String temp = "";
				if (i == 0)//    #
				{
					if (vector.size() == 1) {
						temp = str.substring(index + 1);
						data[1] = temp;
					}
					temp = str.substring(0, index);
					data[0] = temp;
				} else if (i == vector.size() - 1)// //    #
				{
					int preIndex = ((Integer) vector.elementAt(i - 1))
							.intValue();
					temp = str.substring(preIndex + 1, index);//     #     
					data[i] = temp;
					temp = str.substring(index + 1);//     #     
					data[i + 1] = temp;
				} else {
					int preIndex = ((Integer) vector.elementAt(i - 1))
							.intValue();
					temp = str.substring(preIndex + 1, index);//     #     
					data[i] = temp;
				}

			}

		} catch (Exception e) {

			e.printStackTrace();

		} finally {
			return data;
		}
	}