Reference for Processing version 1.2. 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[] p = splitTokens(s, ", ");
println(p[0]); // Prints "a"
println(p[1]); // Prints "b"
println(p[2]); // Prints "c"
println(p[3]); // Prints "d"
Description The splitTokens() function splits a String at one or many character "tokens." The tokens parameter specifies the character or characters to be used as a boundary.

If no tokens character is specified, any whitespace character is used to split. Whitespace characters include tab (\t), line feed (\n), carriage return (\r), form feed (\f), and space. To convert a String to an array of integers or floats, use the datatype conversion functions int() and float() to convert the array of Strings.
Syntax
splitTokens(str)
splitTokens(str, tokens)
Parameters
str the string to be split
tokens list of individual characters that will be used as separators
Returns String[]
Usage Web & Application
Related split()
join()
trim()
Updated on June 14, 2010 12:05:29pm EDT

Creative Commons License