This reference is for Processing 3.0+. If you have a previous version, use the reference included with your software in the Help menu. If you see any errors or have suggestions, please let us know. If you prefer a more technical reference, visit the Processing Core Javadoc and Libraries 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
ReturnsString[]
Relatedsplit()
join()
trim()
Updated on January 21, 2019 10:05:10am EST

Creative Commons License