String
An immutable sequence of Unicode characters.
Static Methods
format
format(template: String, values: any): StringFormats the String as a template, substituting indexed placeholders with the provided values.
Placeholder syntax: {N} or {N, number} or {N, number, specifier} where N is the zero-based index into values.
Number specifiers (used as {N, number, specifier}): - (omitted) — thousands separator, up to 3 decimal places - integer — round to integer, thousands separator - currency — prefix $, exactly 2 decimal places, thousands separator - percent — multiply by 100, append % - pattern — custom decimal-format pattern (see below)
Custom number pattern characters: - # — optional digit (trailing zeros omitted) - 0 — required digit (decimal part padded with 0) - , — grouping separator; group size = number of digits after , in the integer part - . — decimal point - % — multiply value by 100 and append % - Any other character becomes a literal prefix or suffix - 'text' — literal text (suppresses placeholder parsing inside quotes) - '' — literal single-quote character
na values render as "Na".
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
template | String | The format template string containing {N} placeholders. | |
values | any | Variable number of values to substitute into the template. |
Returns: String
format_time
format_time(
time: int,
format: String,
timezone: String = symbol_info.timezone
): StringFormats a timestamp (in milliseconds since epoch) into a String using a pattern of format tokens and a timezone.
Date tokens: - yyyy — 4-digit year (e.g. 2024) - yy — 2-digit year (e.g. 24) - MM — month with leading zero (01–12) - M — month without leading zero (1–12) - dd — day of month with leading zero (01–31) - d — day of month without leading zero (1–31)
Time tokens: - HH — hour, 24-hour clock, with leading zero (00–23) - H — hour, 24-hour clock, without leading zero (0–23) - hh — hour, 12-hour clock, with leading zero (01–12) - h — hour, 12-hour clock, without leading zero (1–12) - a — AM/PM indicator - mm — minutes with leading zero (00–59) - m — minutes without leading zero (0–59) - ss — seconds with leading zero (00–59) - s — seconds without leading zero (0–59) - S — tenths of a second (1 digit) - SS — hundredths of a second (2 digits) - SSS — milliseconds (3 digits)
Timezone token: - Z — UTC offset in ±HHmm form (e.g. +0000, -0530)
Any character that is not a format token is output as a literal (e.g. -, :, ., space). The characters y, z are reserved and must not be used alone (only yy/yyyy are valid; z is always an error).
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
time | int | The timestamp in milliseconds since epoch to format. | |
format | String | The format pattern string (see token table above). | |
timezone | String | symbol_info.timezone | The timezone for the output (e.g. "UTC+8", "UTC-5:30"). Defaults to symbol_info.timezone. |
Returns: String
from
Converts an integer to a String using a custom number pattern. The format string uses the same pattern syntax as the {N, number, pattern} specifier in format:
#— optional digit (trailing zeros omitted) -0— required digit (decimal part padded with0) -,— grouping separator; group size = digits after,in the integer part -.— decimal point -%— multiply value by 100 and append%- Any other character becomes a literal prefix or suffix -'text'— literal text -''— literal single-quote character
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
value | int | The integer value to convert. | |
format | String | The number pattern string controlling the output format. |
Returns: String
Methods
contains
contains(self: String, str: String): boolChecks if the String contains the specified substring.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
self | String | ||
str | String | The substring to search for. |
Returns: bool
ends_with
ends_with(self: String, str: String): boolChecks if the String ends with the specified suffix.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
self | String | ||
str | String | The suffix to search for. |
Returns: bool
See Also: String.starts_with
index_of
index_of(self: String, str: String): intReturns the zero-based index of the first occurrence of a substring, or na if not found.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
self | String | ||
str | String | The substring to search for. |
Returns: int
length
length(self: String): intReturns the length of the String.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
self | String |
Returns: int
lower
lower(self: String): StringConverts all characters in the String to lowercase.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
self | String |
Returns: String
match
match(self: String, regex: String): StringReturns the matched substring if the String matches a regex pattern, or an empty String otherwise.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
self | String | ||
regex | String | The regular expression pattern to match. |
Returns: String
pad_end
pad_end(self: String, len: int, fill: String = " "): StringRight-pads the String with fill until it reaches at least len characters.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
self | String | ||
len | int | The minimum target length in characters. | |
fill | String | " " | The padding String. Defaults to " ". |
Returns: String
See Also: String.pad_start
pad_start
pad_start(self: String, len: int, fill: String = " "): StringLeft-pads the String with fill until it reaches at least len characters.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
self | String | ||
len | int | The minimum target length in characters. | |
fill | String | " " | The padding String. Defaults to " ". |
Returns: String
See Also: String.pad_end
repeat
repeat(self: String, repeat: int): StringReturns a new String consisting of the String repeated a specified number of times.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
self | String | ||
repeat | int | The number of times to repeat the String. |
Returns: String
replace
replace(
self: String,
target: String,
replacement: String,
occurrence: int = 0
): StringReplaces the N-th occurrence of a target substring with a replacement.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
self | String | ||
target | String | The substring to be replaced. | |
replacement | String | The replacement substring. | |
occurrence | int | 0 | N-th occurrence to replace (0-indexed). Defaults to 0. |
Returns: String
See Also: String.replace_all
replace_all
replace_all(self: String, target: String, replacement: String): StringReplaces all occurrences of a target substring with a replacement.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
self | String | ||
target | String | The substring to be replaced. | |
replacement | String | The replacement substring. |
Returns: String
See Also: String.replace
split
split(self: String, separator: String): Array<String>Splits the String into an array of substrings based on a separator.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
self | String | ||
separator | String | The separator String to split on. |
starts_with
starts_with(self: String, str: String): boolChecks if the String starts with the specified prefix.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
self | String | ||
str | String | The prefix to search for. |
Returns: bool
See Also: String.ends_with
substring
substring(self: String, begin_pos: int, end_pos: int): StringReturns a substring from begin_pos to end_pos (exclusive).
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
self | String | ||
begin_pos | int | The starting position (inclusive). | |
end_pos | int | The ending position (exclusive). |
Returns: String
to_number
to_number(self: String): floatConverts the String to a floating-point number.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
self | String |
Returns: float — The parsed float value, or na if the String cannot be parsed.
trim
trim(self: String): StringTrims leading and trailing whitespace from the String.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
self | String |
Returns: String
See Also: String.trim_start, String.trim_end
trim_end
trim_end(self: String): StringTrims trailing whitespace from the String.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
self | String |
Returns: String
See Also: String.trim, String.trim_start
trim_start
trim_start(self: String): StringTrims leading whitespace from the String.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
self | String |
Returns: String
See Also: String.trim, String.trim_end
upper
upper(self: String): StringConverts all characters in the String to uppercase.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
self | String |
Returns: String

