-
Notifications
You must be signed in to change notification settings - Fork 24
String Functions
string
values have the following functions defined.
- charAt
- charCodeAt
- contains
- endsWith
- indexOf
- insert
- lastIndexOf
- normalize
- replace
- split
- startsWith
- substring
- toUpper
- toLower
- trim
- length
- format
- getEnumerator
charAt(index: number): string
Returns the character from the string at index.
charCodeAt(index: number): number
Returns the character code from the string at index.
contains(value: string): bool
Returns true if the value occurs within the string.
endsWith(value: string): bool
Returns true if the string ends with the value.
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(index: number, value: string): string
Returns a new string with the value inserted at the given index.
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(): string
Returns a new instance of the string in Unicode normalization form C.
replace(oldValue: string, newValue: string): string
Returns a new string where all occurrences of the old value are replaced with the new value.
split(separator: string): array
Splits the string at every occurrence of the separator and returns an array of strings.
startsWith(value: string): bool
Returns true if the string starts with the value.
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(): string
Returns a new string with all characters changed to uppercase.
toLower(): string
Returns a new string with all characters changed to lowercase.
trim(): string
Returns a new string with leading and trailing whitespace characters removed.
length(): number
Returns the number of characters in the string.
format(...args: any): string
Formats the string with string.Format
.
getEnumerator(): object
Returns an enumerator for iterating over characters in the string. Values will be returned as 1-length strings.