Name
charAt — Return the character at a given position in a string
Usage
String.charAt(str, index)
: Stringstr
: Numberindex
Description
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.
Examples
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
Get Learning WML, and WMLScript now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.