Learning Examples | Foundations | Hacking | Links
Examples > Strings
The String function substring() is closely related to charAt(), startsWith() and endsWith(). It allows you to look for an instance of a particular substring within a given String.
There is no circuit for this example, though your Arduino must be connected to your computer via USB.
image developed using Fritzing. For more circuit examples, see the Fritzing project page
substring() with only one parameter looks for a given substring from the position given to the end of the string. It expects that the substring extends all the way to the end of the String. For example:
l after the htm in the String.
substring() with two parameters looks for a given substring from the first parameter to the second. For example:
This looks for the word text from positions 14 through 18 of the String.
Caution:
make sure your index values are within the String's length or you'll get unpredictable results. This kind of error can be particularly hard to find with the second instance of substring() if the starting position is less than the String's length, but the ending position isn't.