Skip to content

str

Functions

contains

pine
str.contains(string source, string str) → 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

pine
str.endswith(string source, string str) → 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

pine
str.format(string format, any values) → 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

pine
str.format_time(
    int time,
    string format,
    string timezone = 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

pine
str.length(string str) → int

Returns the length of the given string.

Parameters

NameTypeDefaultDescription
strstringThe string whose length is to be determined.

Returns: int


lower

pine
str.lower(string str) → string

Converts all characters in the string to lowercase.

Parameters

NameTypeDefaultDescription
strstringThe string to convert to lowercase.

Returns: string


match

pine
str.match(string source, string regex) → 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

pine
str.pos(string source, string str) → 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

pine
str.repeat(string source, int repeat) → 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

pine
str.replace(
    string source,
    string target,
    string replacement,
    int occurrence = 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

pine
str.replace_all(string source, string target, string replacement) → 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

pine
str.split(string source, string separator) → 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

pine
str.startswith(string source, string str) → 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

pine
str.substring(string source, int begin_pos, int end_pos) → 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

pine
str.tonumber(string str) → 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 a value to its string representation.

Parameters

NameTypeDefaultDescription
valueTThe value to convert to string.

Returns: string


trim

pine
str.trim(string str) → string

Trims leading and trailing whitespace from the given string.

Parameters

NameTypeDefaultDescription
strstringThe string to trim.

Returns: string


upper

pine
str.upper(string str) → string

Converts all characters in the string to uppercase.

Parameters

NameTypeDefaultDescription
strstringThe string to convert to uppercase.

Returns: string

基於 MIT 許可證發佈。