Hide minor edits - Show changes to markup
(:source http://github.com/arduino/Arduino/raw/master/build/shared/examples/8.Strings/StringSubstring/StringSubstring.ino lang=arduino tabwidth=4:)
(:source http://github.com/arduino/Arduino/raw/master/build/shared/examples/08.Strings/StringSubstring/StringSubstring.ino lang=arduino tabwidth=4:)
(:source http://github.com/arduino/Arduino/raw/master/build/shared/examples/8.Strings/StringSubstring/StringSubstring.pde lang=arduino tabwidth=4:)
(:source http://github.com/arduino/Arduino/raw/master/build/shared/examples/8.Strings/StringSubstring/StringSubstring.ino lang=arduino tabwidth=4:)
(:sourceend:)(:divend:)
(:sourceend:) (:divend:)
(:div class=BOM :)
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.
(:div class=BOM :)
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.
No external hardware is required.
(:div class=circuit :) 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
(:divend:)
(:div class=circuit :) There is no circuit for this example. (:divend:)
[@
(:source lang=arduino tabwidth=4:)
@]
(:sourceend:)
[@
(:source lang=arduino tabwidth=4:)
@]
(:sourceend:)
[@
(:source lang=arduino tabwidth=4:)
@] (:divend:)
(:sourceend:)(:divend:)
(:source http://github.com/arduino/Arduino/raw/master/build/shared/examples/8.Strings/StringSubstring/StringSubstring.pde lang=arduino tabwidth=4:)
(:source http://github.com/arduino/Arduino/raw/master/build/shared/examples/8.Strings/StringSubstring/StringSubstring.pde lang=arduino tabwidth=4:)
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.
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.
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.
(:div class=BOM :)
No external hardware is required. (:divend:)
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:
(:div class=code :)
String stringOne = "Content-Type: text/html";
// substring(index) looks for the substring from the index position to the end:
if (stringOne.substring(19) == "html") {
}
is true, while
String stringOne = "Content-Type: text/html";
// substring(index) looks for the substring from the index position to the end:
if (stringOne.substring(19) == "htm") {
}
is not true, because there's an l after the htm in the String.
(:divend:)
substring() with two parameters looks for a given substring from the first parameter to the second. For example:
(:div class=code :)
String stringOne = "Content-Type: text/html";
// you can also look for a substring in the middle of a string:
if (stringOne.substring(14,18) == "text") {
}
(:divend:)
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.
(:div class=circuit :) There is no circuit for this example. (:divend:)
(:div class=code :)
(:source