O'Reilly logo

Learning WML, and WMLScript by Martin Frost

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

charAt — Return the character at a given position in a string

Usage

String.charAt(str, index)

str : String

index : Number

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required