Skip to content

str

Functions

contains

navi
str.contains(source: string, str: string): bool

Checks if the source string contains the specified substring.

Parameters

NameTypeDefaultDescription
sourcestringThe string to search within.
strstringThe substring to search for.

Returns: bool


endswith

navi
str.endswith(source: string, str: string): bool

Checks if the source string ends with the specified substring.

Parameters

NameTypeDefaultDescription
sourcestringThe string to check.
strstringThe suffix to search for.

Returns: bool


format

navi
str.format(format: string, values: any): string

Formats a string using the given format and values.

Parameters

NameTypeDefaultDescription
formatstringThe format string.
valuesanyVariable number of values to format into the string.

Returns: string


format_time

navi
str.format_time(
    time: int,
    format: string,
    timezone: string = syminfo.timezone
  ): string

Formats 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

NameTypeDefaultDescription
timeintThe timestamp in milliseconds since epoch to format.
formatstringThe format string for the conversion.
timezonestringsyminfo.timezoneThe timezone to use for formatting.

Returns: string


length

navi
str.length(str: string): int

Returns the length of the given string.

Parameters

NameTypeDefaultDescription
strstringThe string whose length is to be determined.

Returns: int


lower

navi
str.lower(str: string): string

Converts all characters in the string to lowercase.

Parameters

NameTypeDefaultDescription
strstringThe string to convert to lowercase.

Returns: string


match

navi
str.match(source: string, regex: string): string

Returns the new substring of the source string if it matches a regex regular expression, an empty string otherwise.

Parameters

NameTypeDefaultDescription
sourcestringThe string to search.
regexstringThe regular expression pattern to match.

Returns: string — The matched substring, or an empty string if no match is found.


pos

navi
str.pos(source: string, str: string): int

Returns the position of the first occurrence of a substring in a string, or na if not found.

Parameters

NameTypeDefaultDescription
sourcestringThe string to search within.
strstringThe substring to search for.

Returns: int — The zero-based index of the first occurrence, or na if not found.


repeat

navi
str.repeat(source: string, repeat: int): string

Returns a new string consisting of the source string repeated a specified number of times.

Parameters

NameTypeDefaultDescription
sourcestringThe string to repeat.
repeatintThe number of times to repeat the string.

Returns: string


replace

navi
str.replace(
    source: string,
    target: string,
    replacement: string,
    occurrence: int = 0
  ): string

Replaces occurrences of a target substring within the source string with a replacement substring.

Parameters

NameTypeDefaultDescription
sourcestringThe original string in which to perform the replacement.
targetstringThe substring to be replaced.
replacementstringThe substring to replace the target with.
occurrenceint0N-th occurrence of the target string to replace. Indexing starts at 0 for the first match.

Returns: string


replace_all

navi
str.replace_all(source: string, target: string, replacement: string): string

Replaces all occurrences of a target substring within the source string with a replacement substring.

Parameters

NameTypeDefaultDescription
sourcestringThe original string in which to perform the replacement.
targetstringThe substring to be replaced.
replacementstringThe substring to replace the target with.

Returns: string


split

navi
str.split(source: string, separator: string): Array<string>

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

Parameters

NameTypeDefaultDescription
sourcestringThe string to split.
separatorstringThe separator string to split on.

Returns: Array<string>


startswith

navi
str.startswith(source: string, str: string): bool

Checks if the source string starts with the specified substring.

Parameters

NameTypeDefaultDescription
sourcestringThe string to check.
strstringThe prefix to search for.

Returns: bool


substring

navi
str.substring(source: string, begin_pos: int, end_pos: int): string

Returns a substring of the source string from begin_pos to end_pos (exclusive).

Parameters

NameTypeDefaultDescription
sourcestringThe string to extract from.
begin_posintThe starting position (inclusive).
end_posintThe ending position (exclusive).

Returns: string


tonumber

navi
str.tonumber(str: string): float

Converts a string to a floating-point number.

Parameters

NameTypeDefaultDescription
strstringThe 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

NameTypeDefaultDescription
valueintThe integer value to convert.
formatstringThe format string for the conversion.

Returns: string

Converts a float to string with the given format.

Parameters

NameTypeDefaultDescription
valuefloatThe float value to convert.
formatstringThe format string for the conversion.

Returns: string

Converts an integer to string using a Format constant.

Parameters

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

Returns: string

Converts a float to string using a Format constant.

Parameters

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

Returns: string

Converts a value to its string representation.

Parameters

NameTypeDefaultDescription
valueTThe value to convert to string.

Returns: string


trim

navi
str.trim(str: string): string

Trims leading and trailing whitespace from the given string.

Parameters

NameTypeDefaultDescription
strstringThe string to trim.

Returns: string


upper

navi
str.upper(str: string): string

Converts all characters in the string to uppercase.

Parameters

NameTypeDefaultDescription
strstringThe string to convert to uppercase.

Returns: string

Released under the MIT License.