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.

Class

String

Name

indexOf()

Examples
String str = "CCCP";
int p1 = str.indexOf("C");
int p2 = str.indexOf("P");
int p3 = str.indexOf("CP");
println(p1 + ":" + p2 + ":" + p3);  // Prints "0:3:2"
Description Tests to see if a substring is embedded in a String, and returns the index position of the first occurrence of the substring defined in the str parameter. If the str substring is not found within the String, -1 is returned.
Syntax
str.indexOf(str)
str.indexOf(str, fromIndex)
Parameters
str String: any variable of type String
str String: the substring to search
fromIndex int: the index from which to start the search
Updated on August 17, 2018 03:36:37pm EDT

Creative Commons License