charAt

Summary

Extracts the character from a given position in the string.

Usage

public char+ charAt(int index)

Returns

The character at the given position. If the position is invalid, undefined will be returned.

Parameters

index

The position in the string to get the character.

Description

Extracts the character from a given position in the string. If the position is invalid (e.g. the provided position is a negative number or goes beyond the end of the string), undefined will be returned.

Performance

This method uses existent types for safety, which requires runtime bounds checking. In browser environments, where performance is critical, consider casting the string to external before calling charAt on it. In other environments, casting to external may not provide a discernable performance improvement, and it may even decrease performance.

Examples

Basic Usage
1
2
3
4
5
6
import System;
 
string abc = "abc";
Console.log(abc.charAt(0)); // `a`
Console.log(abc.charAt(1)); // `b`
Console.log(abc.charAt(2)); // `c`

Share

HTML | BBCode | Direct Link