Skip to content

String

An immutable sequence of Unicode characters.

Static Methods

format

navi
format(template: String, values: any): String

Formats 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

NameTypeDefaultDescription
templateStringThe format template string containing {N} placeholders.
valuesanyVariable number of values to substitute into the template.

Returns: String


format_time

navi
format_time(
    time: int,
    format: String,
    timezone: String = symbol_info.timezone
  ): String

Formats 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 (0112) - M — month without leading zero (112) - dd — day of month with leading zero (0131) - d — day of month without leading zero (131)

Time tokens: - HH — hour, 24-hour clock, with leading zero (0023) - H — hour, 24-hour clock, without leading zero (023) - hh — hour, 12-hour clock, with leading zero (0112) - h — hour, 12-hour clock, without leading zero (112) - a — AM/PM indicator - mm — minutes with leading zero (0059) - m — minutes without leading zero (059) - ss — seconds with leading zero (0059) - s — seconds without leading zero (059) - 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

NameTypeDefaultDescription
timeintThe timestamp in milliseconds since epoch to format.
formatStringThe format pattern string (see token table above).
timezoneStringsymbol_info.timezoneThe 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 with 0) - , — 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

NameTypeDefaultDescription
valueintThe integer value to convert.
formatStringThe number pattern string controlling the output format.

Returns: String

Converts a float 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 with 0) - , — 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

NameTypeDefaultDescription
valuefloatThe float value to convert.
formatStringThe number pattern string controlling the output format.

Returns: String

Converts an integer to a String using a Format constant. The format constant controls how the number is presented: - Format.Inherit — inherits formatting from the enclosing series context - Format.Price — formatted as a price (symbol-dependent precision) - Format.Volume — formatted as a volume figure (compact notation for large numbers) - Format.Percent — formatted as a percentage - Format.Mintick — rounded to the symbol's mintick with trailing zeros preserved

Parameters

NameTypeDefaultDescription
valueintThe integer value to convert.
formatFormatThe Format constant controlling formatting.

Returns: String

Converts a float to a String using a Format constant. The format constant controls how the number is presented: - Format.Inherit — inherits formatting from the enclosing series context - Format.Price — formatted as a price (symbol-dependent precision) - Format.Volume — formatted as a volume figure (compact notation for large numbers) - Format.Percent — formatted as a percentage - Format.Mintick — rounded to the symbol's mintick with trailing zeros preserved

Parameters

NameTypeDefaultDescription
valuefloatThe float value to convert.
formatFormatThe Format constant controlling formatting.

Returns: String

Converts any value to its String representation.

Parameters

NameTypeDefaultDescription
valueTThe value to convert to String.

Returns: String

Methods

contains

navi
contains(self: String, str: String): bool

Checks if the String contains the specified substring.

Parameters

NameTypeDefaultDescription
selfString
strStringThe substring to search for.

Returns: bool


ends_with

navi
ends_with(self: String, str: String): bool

Checks if the String ends with the specified suffix.

Parameters

NameTypeDefaultDescription
selfString
strStringThe suffix to search for.

Returns: bool

See Also: String.starts_with


index_of

navi
index_of(self: String, str: String): int

Returns the zero-based index of the first occurrence of a substring, or na if not found.

Parameters

NameTypeDefaultDescription
selfString
strStringThe substring to search for.

Returns: int


length

navi
length(self: String): int

Returns the length of the String.

Parameters

NameTypeDefaultDescription
selfString

Returns: int


lower

navi
lower(self: String): String

Converts all characters in the String to lowercase.

Parameters

NameTypeDefaultDescription
selfString

Returns: String


match

navi
match(self: String, regex: String): String

Returns the matched substring if the String matches a regex pattern, or an empty String otherwise.

Parameters

NameTypeDefaultDescription
selfString
regexStringThe regular expression pattern to match.

Returns: String


pad_end

navi
pad_end(self: String, len: int, fill: String = " "): String

Right-pads the String with fill until it reaches at least len characters.

Parameters

NameTypeDefaultDescription
selfString
lenintThe minimum target length in characters.
fillString" "The padding String. Defaults to " ".

Returns: String

See Also: String.pad_start


pad_start

navi
pad_start(self: String, len: int, fill: String = " "): String

Left-pads the String with fill until it reaches at least len characters.

Parameters

NameTypeDefaultDescription
selfString
lenintThe minimum target length in characters.
fillString" "The padding String. Defaults to " ".

Returns: String

See Also: String.pad_end


repeat

navi
repeat(self: String, repeat: int): String

Returns a new String consisting of the String repeated a specified number of times.

Parameters

NameTypeDefaultDescription
selfString
repeatintThe number of times to repeat the String.

Returns: String


replace

navi
replace(
    self: String,
    target: String,
    replacement: String,
    occurrence: int = 0
  ): String

Replaces the N-th occurrence of a target substring with a replacement.

Parameters

NameTypeDefaultDescription
selfString
targetStringThe substring to be replaced.
replacementStringThe replacement substring.
occurrenceint0N-th occurrence to replace (0-indexed). Defaults to 0.

Returns: String

See Also: String.replace_all


replace_all

navi
replace_all(self: String, target: String, replacement: String): String

Replaces all occurrences of a target substring with a replacement.

Parameters

NameTypeDefaultDescription
selfString
targetStringThe substring to be replaced.
replacementStringThe replacement substring.

Returns: String

See Also: String.replace


split

navi
split(self: String, separator: String): Array<String>

Splits the String into an array of substrings based on a separator.

Parameters

NameTypeDefaultDescription
selfString
separatorStringThe separator String to split on.

Returns: Array<String>


starts_with

navi
starts_with(self: String, str: String): bool

Checks if the String starts with the specified prefix.

Parameters

NameTypeDefaultDescription
selfString
strStringThe prefix to search for.

Returns: bool

See Also: String.ends_with


substring

navi
substring(self: String, begin_pos: int, end_pos: int): String

Returns a substring from begin_pos to end_pos (exclusive).

Parameters

NameTypeDefaultDescription
selfString
begin_posintThe starting position (inclusive).
end_posintThe ending position (exclusive).

Returns: String


to_number

navi
to_number(self: String): float

Converts the String to a floating-point number.

Parameters

NameTypeDefaultDescription
selfString

Returns: float — The parsed float value, or na if the String cannot be parsed.


trim

navi
trim(self: String): String

Trims leading and trailing whitespace from the String.

Parameters

NameTypeDefaultDescription
selfString

Returns: String

See Also: String.trim_start, String.trim_end


trim_end

navi
trim_end(self: String): String

Trims trailing whitespace from the String.

Parameters

NameTypeDefaultDescription
selfString

Returns: String

See Also: String.trim, String.trim_start


trim_start

navi
trim_start(self: String): String

Trims leading whitespace from the String.

Parameters

NameTypeDefaultDescription
selfString

Returns: String

See Also: String.trim, String.trim_end


upper

navi
upper(self: String): String

Converts all characters in the String to uppercase.

Parameters

NameTypeDefaultDescription
selfString

Returns: String