String class

charAt()

Access a particular character of the String.

// SYNTAX
string.charAt(n)

// PROTOTYPE
char charAt(unsigned int index) const;

Parameters:

  • string: a variable of type String
  • n: the character to access

Returns: the n'th character of the String (n is zero-based, the first character of the string is index 0).

If the index n is out of bounds (< 0 or >= length), then the value 0 is returned.

You can also use operator[]. The expression string[0] and string.charAt(0) both return the first character of string.