str
Functions
contains
str.contains(string source, string str) → boolChecks if the source string contains the specified substring.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
source | string | The string to search within. | |
str | string | The substring to search for. |
Returns: bool
endswith
str.endswith(string source, string str) → boolChecks if the source string ends with the specified substring.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
source | string | The string to check. | |
str | string | The suffix to search for. |
Returns: bool
format
str.format(string format, any values) → stringFormats a string using the given format and values.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
format | string | The format string. | |
values | any | Variable number of values to format into the string. |
Returns: string
format_time
str.format_time(
int time,
string format,
string timezone = syminfo.timezone
) → stringFormats a timestamp (in milliseconds since epoch) into a string based on the provided format and timezone.
The 'M', 'd', 'h', 'H', 'm' and 's' tokens can all be doubled to generate leading zeros. For example, the month of January will display as 1 with 'M', or 01 with 'MM'. The most frequently used formatting tokens are: 'y' - Year. Use 'yy' to output the last two digits of the year or 'yyyy' to output all four. Year 2000 will be 00 with 'yy' or 2000 with 'yyyy'. 'M' - Month. Not to be confused with lowercase 'm', which stands for minute. 'd' - Day of the month. 'a' - AM/PM postfix. 'h' - Hour in the 12-hour format. The last hour of the day will be '11' in this format. 'H' - Hour in the 24-hour format. The last hour of the day will be '23' in this format. 'm' - Minute. 's' - Second. 'S' - Fractions of a second. 'Z' - Timezone, the HHmm offset from UTC, preceded by either '+' or '-'.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
time | int | The timestamp in milliseconds since epoch to format. | |
format | string | The format string for the conversion. | |
timezone | string | syminfo.timezone | The timezone to use for formatting. |
Returns: string
length
str.length(string str) → intReturns the length of the given string.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
str | string | The string whose length is to be determined. |
Returns: int
lower
str.lower(string str) → stringConverts all characters in the string to lowercase.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
str | string | The string to convert to lowercase. |
Returns: string
match
str.match(string source, string regex) → stringReturns the new substring of the source string if it matches a regex regular expression, an empty string otherwise.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
source | string | The string to search. | |
regex | string | The regular expression pattern to match. |
Returns: string — The matched substring, or an empty string if no match is found.
pos
str.pos(string source, string str) → intReturns the position of the first occurrence of a substring in a string, or na if not found.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
source | string | The string to search within. | |
str | string | The substring to search for. |
Returns: int — The zero-based index of the first occurrence, or na if not found.
repeat
str.repeat(string source, int repeat) → stringReturns a new string consisting of the source string repeated a specified number of times.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
source | string | The string to repeat. | |
repeat | int | The number of times to repeat the string. |
Returns: string
replace
str.replace(
string source,
string target,
string replacement,
int occurrence = 0
) → stringReplaces occurrences of a target substring within the source string with a replacement substring.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
source | string | The original string in which to perform the replacement. | |
target | string | The substring to be replaced. | |
replacement | string | The substring to replace the target with. | |
occurrence | int | 0 | N-th occurrence of the target string to replace. Indexing starts at 0 for the first match. |
Returns: string
replace_all
str.replace_all(string source, string target, string replacement) → stringReplaces all occurrences of a target substring within the source string with a replacement substring.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
source | string | The original string in which to perform the replacement. | |
target | string | The substring to be replaced. | |
replacement | string | The substring to replace the target with. |
Returns: string
split
str.split(string source, string separator) → array<string>Splits the source string into an array of substrings based on the specified separator.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
source | string | The string to split. | |
separator | string | The separator string to split on. |
Returns: array<string>
startswith
str.startswith(string source, string str) → boolChecks if the source string starts with the specified substring.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
source | string | The string to check. | |
str | string | The prefix to search for. |
Returns: bool
substring
str.substring(string source, int begin_pos, int end_pos) → stringReturns a substring of the source string from begin_pos to end_pos (exclusive).
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
source | string | The string to extract from. | |
begin_pos | int | The starting position (inclusive). | |
end_pos | int | The ending position (exclusive). |
Returns: string
tonumber
str.tonumber(string str) → floatConverts a string to a floating-point number.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
str | string | The string to convert to a number. |
Returns: float — The parsed float value, or na if the string cannot be parsed as a number.
tostring
Converts a value to its string representation.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
value | int | The integer value to convert. | |
format | string | The format string for the conversion. |
Returns: string
trim
str.trim(string str) → stringTrims leading and trailing whitespace from the given string.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
str | string | The string to trim. |
Returns: string
upper
str.upper(string str) → stringConverts all characters in the string to uppercase.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
str | string | The string to convert to uppercase. |
Returns: string