TruWorlds

String

Accessed via string

The string module provides functions for working with strings in TruScript.

Functions

string.is_empty(str: string) Returns bool

Returns true if the string is empty, and false otherwise.

string.length(str: string) Returns int

Returns the number of characters in the string.

string.uppercase(str: string) Returns string

Returns a new string with all characters in the original string converted to uppercase.

string.lowercase(str: string) Returns string

Returns a new string with all characters in the original string converted to lowercase.

string.trim(str: string) Returns string

Returns a new string with all leading and trailing whitespace removed from the original string.

string.substring(str: string, startIndex: int, length: int) Returns string

Returns a new string that is a substring of the original string, starting at the specified index and with the specified length.

string.replace(str: string, oldValue: string, newValue: string) Returns string

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

string.split(str: string, separator: string) Returns string[]

Splits the string into an array of substrings based on the specified separator.

string.join(strArray: array, separator: string)

Joins an array of strings into a single string, with the specified separator between each string.

string.contains(str: string, substring: string)

Returns true if the string contains the specified substring, and false otherwise.

string.starts_with(str: string, prefix: string) Returns bool

Returns true if the string starts with the specified prefix, and false otherwise.

string.ends_with(str: string, suffix: string) Returns bool

Returns true if the string ends with the specified suffix, and false otherwise.

string.index_of(str: string, substring: string) Returns int

Returns the index of the first occurrence of the specified substring in the string, or -1 if the substring is not found.

string.last_index_of(str: string, substring: string) Returns int

Returns the index of the last occurrence of the specified substring in the string, or -1 if the substring is not found.

string.reverse(str: string) Returns string

Returns a new string with the characters in the original string in reverse order.

string.repeat(str: string, count: int) Returns string

Returns a new string that is the original string repeated the specified number of times.

string.pad_start(str: string, totalLength: int, paddingChar: string) Returns string

Returns a new string that is the original string padded at the start with the specified character until it reaches the specified total length.

string.pad_end(str: string, totalLength: int, paddingChar: string) Returns string

Returns a new string that is the original string padded at the end with the specified character until it reaches the specified total length.

string.matches(str: string, pattern: string) Returns bool

Returns true if the string matches the specified regular expression (RegEx) pattern, and false otherwise.