charAt — Return the character at a given position in a string
String.charAt(str, index)
: Stringstr
: Numberindex
Extracts the single character at the specified
index
from the string
str
, and returns it as a single-character
string. (The first character in the string has index zero.) If index
is a floating-point number, it’s converted to an integer with
Float.int( )
before being used. If
index
is out of range (less than zero or
past the end of the string), the empty string is returned.
If the arguments can’t be converted to the correct types,
invalid
is returned.
String.charAt("Example", 0)
returns string "E"
String.charAt("Example", 3)
returns string "m"
String.charAt("Example", 6)
returns string "e"
String.charAt("Example", 7)
returns string ""
String.charAt "Example", -1)
returns string ""
String.charAt(42, 1)
returns string "2"
String.charAt(false, 4)
returns string "e"
String.charAt(invalid, 0)
returns invalid
String.charAt("foo", "bar")
returns invalid
No credit card required