string class methodsLast modified: 2026-10-22
length - expects nothing, and returns the number of
characters in the calling string object
const string HUMBOLDT_LOC = "Arcata";
HUMBOLDT_LOC.length() == 6 at - expects an int,
a desired position within a string, and returns
a char, the single character at that position within
the calling string. (BUT: the position of the first character
in the string is 0...!)
HUMBOLDT_LOC.at(0) == 'A'
HUMBOLDT_LOC.at(2) == 'c' substr - 1-argument version:
expects an int, a desired starting position,
and returns the string starting at that position in the calling string
and going until the end of the calling string. (BUT: the position of the first
character in the string is 0...!)
HUMBOLDT_LOC.substr(3) == "ata" substr - 2-argument version:
expects a starting position and a
desired length (a desired number of characters to grab), and
returns the string starting at that position in
the calling string and grabbing that many characters
(or until the end of the calling string, whatever comes first).
(BUT: the position of the first character in the string is 0...!)
HUMBOLDT_LOC.substr(2, 3) == "cat"