This reference is for Processing 2.0+. If you have a previous version, use the reference included with your software. If you see any errors or have suggestions, please let us know. If you prefer a more technical reference, visit the Processing Javadoc.

Name | ### splitTokens()
Examples |
    String t = "a b";
    String[] q = splitTokens(t);
    println(q[0]);  // Prints "a"
    println(q[1]);  // Prints "b"
    // Despite the bad formatting, the data is parsed correctly.
    // The ", " as delimiter means to break whenever a comma *or*
    // a space is found in the String. Unlike the split() function,
    // multiple adjacent delimiters are treated as a single break.
    String s = "a, b c ,,d ";
    String[] q = splitTokens(s, ", ");
    println(q.length + " values found");  // Prints "4 values found"
    println(q[0]);  // Prints "a"
    println(q[1]);  // Prints "b"
    println(q[2]);  // Prints "c"
    println(q[3]);  // Prints "d"
Description | The splitTokens() function splits a String at one or many character delimiters or "tokens." The delim parameter specifies the character or characters to be used as a boundary. If no delim characters are specified, any whitespace character is used to split. Whitespace characters include tab (\t), line feed (\n), carriage return (\r), form feed (\f), and space. After using this function to parse incoming data, it is common to convert the data from Strings to integers or floats by using the datatype conversion functions int() and float().
Syntax |
    splitTokens(value)
    splitTokens(value, delim)
Parameters |
value | String: the String to be split
delim | String: list of individual characters that will be used as separators
Returns | String[]
Related | split() join() trim()

Updated on October 26, 2013 08:58:31pm PDT