Here you can find the source of splitBySeparator(String line, char sep)
Parameter | Description |
---|---|
line | The String to be seperated. |
sep | The seperator character, eg a comma |
public static String[] splitBySeparator(String line, char sep)
//package com.java2s; /*************************************** * ViPER * * The Video Processing * * Evaluation Resource * * * * Distributed under the GPL license * * Terms available at gnu.org. * * * * Copyright University of Maryland, * * College Park. * ***************************************/ import java.util.*; public class Main { /**/*w w w .j av a 2 s . c o m*/ * Split using a seperator. * * @param line The String to be seperated. * @param sep The seperator character, eg a comma * @return An array of Strings containing the seperated data. * @see #splitBySeparatorAndParen(String line, char sep) */ public static String[] splitBySeparator(String line, char sep) { String newLine = line; Vector temp = new Vector(); while (true) { int separatorIndex = newLine.indexOf(sep); if (separatorIndex == -1) { String lastNum = newLine.substring(separatorIndex + 1); temp.addElement(lastNum.trim()); break; } else { String newNum = newLine.substring(0, separatorIndex); temp.addElement(newNum.trim()); } newLine = newLine.substring(separatorIndex + 1); } String[] result = new String[temp.size()]; for (int i = 0; i < result.length; i++) { result[i] = (String) temp.elementAt(i); } return (result); } }