TruWorlds

String

Accessed via string

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

Functions

string.is_empty(str: string) Returns boolean

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

string.length(str: string) Returns number

Returns the number of characters in the string.

string.upper(str: string) Returns string

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

string.lower(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: number, length: number) 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: string[], separator: string) Returns string

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

string.contains(str: string, value: string) Returns boolean

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

string.starts_with(str: string, value: string) Returns boolean

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

string.ends_with(str: string, value: string) Returns boolean

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

string.index_of(str: string, value: string) Returns number

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, value: string) Returns number

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: number) Returns string

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

string.pad_start(str: string, totalWidth: number, 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 width. When no padding character is given, a space is used.

string.pad_end(str: string, totalWidth: number, 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 width. When no padding character is given, a space is used.

string.match(str: string, regex: string) Returns boolean

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

string.format(formatString: string, ...args) Returns string

Returns a formatted string replacing placeholders ("My name is {0} and I like {1}!") with the remaining arguments.