Search processing.org:

Reference for Processing (BETA) version 0135+. If you have a previous version, use the reference included with your software. If you see any errors or have any comments, let us know.

Name

### splitTokens()

Examples

    String t = "a b";
    String[] q = splitTokens(t);
    println(q[0]); // Prints "a"
    println(q[1]); // Prints "b"

    String s = "a, b c ,,d "; // Despite the bad formatting,
    String[] p = splitTokens(s, ", "); // the data is parsed correctly
    println(p[0]); // Prints "a"
    println(p[1]); // Prints "b"
    println(p[2]); // Prints "c"
    println(p[3]); // Prints "d"

Description

The splitTokens() function allows you to split a String at one or many character "tokens." The tokens parameter specifies the character or characters that mark the boundaries between each data element. If no tokens character is specified, a whitespace character is used as the split character. Whitespace characters include tab (t), line feed (n), carriage return (r), and 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

Usage | Web & Application
Related | split() join() trim()

Updated on February 09, 2008 04:38:52pm PST