Skip to content

String Functions

Rohan Singh edited this page Feb 11, 2022 · 4 revisions

string values have the following functions defined.

charAt

charAt(index: number): string

Returns the character from the string at index.

charCodeAt

charCodeAt(index: number): number

Returns the character code from the string at index.

contains

contains(value: string): bool

Returns true if the value occurs within the string.

endsWith

endsWith(value: string): bool

Returns true if the string ends with the value.

indexOf

indexOf(value: string): number

Returns the index of the first occurrence of the value in the string, or -1 if it was not found.

insert

insert(index: number, value: string): string

Returns a new string with the value inserted at the given index.

lastIndexOf

lastIndexOf(value: string): number

Returns the index of the last occurrence of the value in the string, or -1 if it was not found.

normalize

normalize(): string

Returns a new instance of the string in Unicode normalization form C.

replace

replace(oldValue: string, newValue: string): string

Returns a new string where all occurrences of the old value are replaced with the new value.

split

split(separator: string): array

Splits the string at every occurrence of the separator and returns an array of strings.

startsWith

startsWith(value: string): bool

Returns true if the string starts with the value.

substring

substring(startIndex: number)

Returns part of the string starting at the given index, or an empty string if the starting index is invalid.

substring(startIndex: number, length: number): string

Returns part of the string starting at the given index, up to a maximum length. Will return an empty string if the range is invalid.

toUpper

toUpper(): string

Returns a new string with all characters changed to uppercase.

toLower

toLower(): string

Returns a new string with all characters changed to lowercase.

trim

trim(): string

Returns a new string with leading and trailing whitespace characters removed.

length

length(): number

Returns the number of characters in the string.

format

format(...args: any): string

Formats the string with string.Format.

getEnumerator

getEnumerator(): object

Returns an enumerator for iterating over characters in the string. Values will be returned as 1-length strings.