Java String Tokenize tokenize(String input)

Here you can find the source of tokenize(String input)

Description

Tokenizing helper.

License

Open Source License

Parameter

Parameter Description
input is a line to be tokenized

Return

a String[] of the strings in between the delimiters

Declaration

public static String[] tokenize(String input) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from   w  w  w  . ja v  a2  s .co  m
     * Tokenizing helper.  Works on space, tab and comma separated files.
     * 
     * @param input is a line to be tokenized
     * @return a String[] of the strings in between the delimiters
     */
    public static String[] tokenize(String input) {
        if (input.contains(",")) { // comma delimited
            String[] ret = input.split(",");
            // trim leading whitespace
            for (String s : ret) {
                s.trim();
            }
            return ret;
        } else if (input.contains("\\t")) { // tab delimited
            return input.split("\\t+");
        } else { // whitespace delimited
            return input.trim().split("\\s+");
        }
    }
}

Related

  1. tokenize(final String s)
  2. tokenize(String array, String delimiter)
  3. tokenize(String formula)
  4. tokenize(String in)
  5. tokenize(String input)
  6. tokenize(String input)
  7. tokenize(String input, char by)
  8. tokenize(String input, String delim)
  9. tokenize(String line)