Java String Split by Line splitBySeparator(String line, char sep)

Here you can find the source of splitBySeparator(String line, char sep)

Description

Split using a seperator.

License

GNU General Public License

Parameter

Parameter Description
line The String to be seperated.
sep The seperator character, eg a comma

Return

An array of Strings containing the seperated data.

Declaration

public static String[] splitBySeparator(String line, char sep) 

Method Source Code

//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);
    }
}

Related

  1. split(String line, String seperator)
  2. Split(String line, String sptr)
  3. splitArguments(String commandLine, boolean backslashesAreLiteral)
  4. splitArgumentsBackslashesAreLiteral(String commandLine)
  5. splitByBrackets(String line)
  6. splitBySeparatorAndParen(String line, char sep)
  7. splitBySeparatorQuoteAndParen(String line, char sep)
  8. splitCommandLine(String str, boolean extract)
  9. splitCommaSeparated(String line)