string
The string type is a sequence of characters.
The string library is a standard Lua library which provides functions for the manipulation of strings.
In dreamwork string library contains additional functions.
Classes & types
Fields
| Name | Type | Description |
|---|---|---|
PatternBytes | table<integer, string> | A table of bytes that map to pattern sequences. |
buffer | string.bufferlib | nil | The string buffer library allows high-performance manipulation of string-like data. |
Functions
string.byteMap | Creates a byte map — a lookup table from byte value to true — from a list of individual byte strings and/or byte ranges… |
string.bytePad | Pads a string with a single repeated byte until it reaches desired_length characters, on the left, the right, or both s… |
string.byteRep | Returns a string that is the concatenation of repetitions copies of the byte rep_byte. |
string.byteReplace | Replaces all occurrences of the specified byte within str with replaceable, within the given range. |
string.byteSplit | Splits a string into an array of substrings, breaking at every occurrence of the specified byte within the given range. |
string.comma | Inserts a separator (e.g. a comma) every offset characters, counting from the right end of the string — the typical "th… |
string.contains | Checks if str contains searchable. |
string.containsByte | Checks whether a string contains the specified single byte value, within the given range. |
string.containsBytes | Checks whether a string contains at least one byte that's a member of the given byte map, within the given range. |
string.count | Returns the number of non-overlapping matches of a substring or pattern within a string. |
string.countByte | Returns the total number of occurrences of the specified byte within a string, scanning the whole [start_position, end_… |
string.countConsecutiveByte | Returns the number of consecutive repetitions of the specified byte, starting from start_position and scanning towards… |
string.diff | Computes a Myers diff between two strings. |
string.divide | Splits a string into fixed-size chunks of size bytes each, in order from the start of the string. |
string.escape | Escapes special characters in a string. |
string.escapePattern | Escapes a string so it can be safely embedded in a Lua pattern and matched literally, rather than having its characters… |
string.extract | Finds the first match of searchable within str, removes it from the string, and returns both the remaining string and t… |
string.findByte | Finds the position of the first occurrence of the specified byte value within a string, searching the given range. |
string.fnv0 | Returns the Fowler-Noll-Vo (FNV-0) [deprecated] hash of the string. |
string.fnv1 | Returns the Fowler-Noll-Vo (FNV-1) hash of the string. |
string.fnv1a | Returns the Fowler-Noll-Vo (FNV-1a) hash of the string. |
string.hasPrefix | Checks if the string starts with the prefix, optionally checking at a byte offset into the string rather than from the… |
string.hasSuffix | Checks if the string ends with the suffix, optionally checking with a byte offset from the end of the string rather tha… |
string.indent | Sets a string's leading indentation to exactly size spaces, replacing any existing leading whitespace rather than addin… |
string.indentLines | Indents every line of a string by setting each line's leading whitespace to exactly size spaces (via string.indent), sp… |
string.indexOf | Returns the index of the first occurrence of searchable within str, searching from position onwards. |
string.insert | Inserts value into str at the given index, shifting everything from index onwards to the right. |
string.interpolate | Interpolates a string with the given arguments, replacing {...} placeholders with values from variables, within the giv… |
string.interpolateByte | Replaces occurrences of a specific byte in the string with values from variables, in the order they're found — the firs… |
string.isBytecode | Checks whether a string starts with a LuaJIT bytecode header for the given JIT version. |
string.isEmpty | Checks whether a string is empty, i.e. has no bytes at all. |
string.isNumber | Checks whether a string (or a sub-range of it) can be parsed as a valid number, using the same base auto-detection and… |
string.isURL | Checks whether a string looks like a well-formed URL, matched against a strict pattern rather than resolved or validate… |
string.pack | Packs a sequence of bytes into a string, the inverse of string.unpack. |
string.pad | Pads a string with a repeated padding string until it reaches desired_length characters, on the left, the right, or bot… |
string.purge | Removes every occurrence of the specified byte from a string, within the given range. |
string.quote | Wraps a string in quotes, escaping any quote characters of the same kind already inside it so the result is a syntactic… |
string.random | Generates a random string by repeatedly picking a random character pool and then a random character from it. |
string.remove | Removes the inclusive byte range [start_position, end_position] from a string, returning what remains with the gap clos… |
string.replace | Replaces all occurrences of searchable within str with replaceable. |
string.split | Splits a string into an array of substrings around every occurrence of searchable within the given range. |
string.toNumber | Converts a string, or a sub-range of it, to a number, with automatic base detection when base is omitted. |
string.trim | Removes leading and/or trailing matches of a character set from a string. |
string.trimByte | Removes leading and/or trailing occurrences of a single specific byte from a string, within the given range. |
string.trimSpaces | Removes leading and/or trailing whitespace characters from a string, within the given range, and returns the trimmed st… |
string.unescape | Unescapes special characters in a string. |
string.unIndent | Removes leading whitespace from the start of a single-line string (does not affect subsequent lines if str contains emb… |
string.unindentLines | Removes leading whitespace from every line of a string (via string.unIndent), splitting on \n and rejoining the result… |
string.unpack | Unpacks a string into a sequence of bytes, the inverse of string.pack. |
string.unQuote | Removes a surrounding pair of quotes from a string and unescapes any escaped quote characters of the same kind inside i… |
#string.byteMap
function string.byteMap(...: string | string.ByteMapRange): table<integer, boolean>
Creates a byte map — a lookup table from byte value to true — from a list of individual byte strings and/or byte ranges, for fast byte_map[ byte ] membership checks (e.g. in character-classification helpers like ascii_isSpace).
Each argument is either a single-character string (whose byte is added to the map) or a string.ByteMapRange table with leading_byte/trailing_byte fields giving an inclusive range of single-character strings to add, and an optional step_size (defaults to 1) to skip bytes within that range.
| Name | Type | Description |
|---|---|---|
... | string | string.ByteMapRange | A list of bytes or byte ranges to include in the map. |
| Type | Name | Description |
|---|---|---|
table<integer, boolean> | byte_map | A table mapping each included byte value to true. |
#string.bytePad
function string.bytePad(str: string, desired_length: integer, padding_byte?: integer, left?: boolean, right?: boolean): string
Pads a string with a single repeated byte until it reaches desired_length characters, on the left, the right, or both sides evenly.
Unlike string.pad, which pads with an arbitrary (possibly multi-byte) padding string, this pads with one fixed byte value, which avoids the chunk-size arithmetic string.pad needs and is a cheaper option when a single repeated byte is all that's needed.
If neither left nor right is true, or str is already at least desired_length characters long, str is returned unchanged. When padding both sides and the missing length is odd, the extra byte goes to the right side.
| Name | Type | Description |
|---|---|---|
str | string | The string to pad. |
desired_length | integer | The target length, in bytes, that the result should reach. |
padding_byteoptional | integer | The byte value to pad with. Defaults to 0x20 (space). |
leftoptional | boolean | Whether to add padding on the left side. |
rightoptional | boolean | Whether to add padding on the right side. |
| Type | Name | Description |
|---|---|---|
string | padded_str | The padded string, or str unchanged if no padding was needed or requested. |
#string.byteRep
function string.byteRep(rep_byte: integer, repetitions?: integer): string
Returns a string that is the concatenation of repetitions copies of the byte rep_byte.
Equivalent to string.rep( string.char( rep_byte ), repetitions ). Repetition counts from 1 to 16 are special-cased as direct string_char calls, which JIT-compile to 2-4x faster code than string.rep when rep_byte is constant at the call site; any other count falls back to string.rep( string.char( rep_byte ), repetitions ).
| Name | Type | Description |
|---|---|---|
rep_byte | integer | The byte value to repeat (0-255). |
repetitionsoptional | integer | The number of times to repeat the byte. Defaults to 1. |
| Type | Name | Description |
|---|---|---|
string | rep_str | The byte repeated repetitions times, as a string. |
#string.byteReplace
function string.byteReplace(str: string, searchable_byte?: integer, replaceable?: string, start_position?: integer, end_position?: integer): string
Replaces all occurrences of the specified byte within str with replaceable, within the given range.
Implemented by splitting str around every occurrence of searchable_byte (via byte_split) and rejoining the pieces with replaceable in between — the byte-level counterpart to string.replace, which matches a substring or pattern instead of a single byte value. If searchable_byte is nil, this falls back to byte_split's default of splitting on space (0x20).
| Name | Type | Description |
|---|---|---|
str | string | The string we are seeking to replace an occurrence(s) in. |
searchable_byteoptional | integer | The byte value to find and replace. Defaults to 0x20 (space). |
replaceableoptional | string | What to replace each occurrence with. If nil, occurrences are removed. |
start_positionoptional | integer | The position to start replacing from, inclusive. Matches outside this range are left untouched. |
end_positionoptional | integer | The position to stop replacing at, inclusive. Matches outside this range are left untouched. |
| Type | Name | Description |
|---|---|---|
string | str_replaced | The new string with the occurrences replaced. |
#string.byteSplit
function string.byteSplit(str: string, searchable_byte?: integer, start_position?: integer, end_position?: integer): string[], integer
Splits a string into an array of substrings, breaking at every occurrence of the specified byte within the given range. The delimiter byte itself is not included in any of the resulting segments.
Consecutive delimiter bytes produce empty-string segments rather than being collapsed, so e.g. splitting "a,,b" on , yields { "a", "", "b" }.
| Name | Type | Description |
|---|---|---|
str | string | The string to split. |
searchable_byteoptional | integer | The byte value to split on. Defaults to 0x20 (space). |
start_positionoptional | integer | The position to start splitting from, inclusive. Negative values count from the end of the string. Defaults to 1 (the start of the string). |
end_positionoptional | integer | The position to stop splitting at, inclusive. Negative values count from the end of the string. Defaults to the end of the string. |
| Type | Name | Description |
|---|---|---|
string[] | segments | The resulting array of substrings. |
integer | segment_count | The number of entries in segments. |
#string.comma
function string.comma(str: string, separator?: string, offset?: integer): string
Inserts a separator (e.g. a comma) every offset characters, counting from the right end of the string — the typical "thousands separator" formatting for large numbers (e.g. "1234567" → "1,234,567").
Operates purely on the string as a sequence of characters, with no awareness of numeric structure: it doesn't special-case a leading sign, a decimal point, or non-digit characters, so calling it on something that isn't a plain digit string (e.g. one that already contains a . or -) will insert separators through those characters too, based purely on position from the right.
offset is normalized to a non-negative integer (math_abs + math_floor); an offset of 0 returns str unchanged, since no grouping width is meaningful.
| Name | Type | Description |
|---|---|---|
str | string | The string to format. |
separatoroptional | string | The separator string to insert between groups. Defaults to ",". |
offsetoptional | integer | The number of characters per group, counted from the right. Defaults to 3. Normalized to a non-negative integer; 0 returns str unchanged. |
| Type | Name | Description |
|---|---|---|
string | str | The string with separators inserted every offset characters from the right. |
#string.contains
function string.contains(str: string, searchable: string, with_pattern?: boolean, start_position?: integer): boolean
Checks if str contains searchable.
Wraps string.find and returns true if a match is found at or after start_position. By default the search is treated as a plain substring match; pass with_pattern = true to interpret searchable as a Lua pattern instead.
| Name | Type | Description |
|---|---|---|
str | string | The string to search in. |
searchable | string | The substring or pattern to search for. |
with_patternoptional | boolean | When true, searchable is interpreted as a Lua pattern. Defaults to false (plain match). |
start_positionoptional | integer | The byte position to start searching from. Defaults to 1. Negative values count from the end of the string. |
| Type | Name | Description |
|---|---|---|
boolean | found | true if searchable was found within str, false otherwise. |
#string.containsByte
function string.containsByte(str: string, byte: integer, start_position?: integer, end_position?: integer): boolean
Checks whether a string contains the specified single byte value, within the given range.
The single-byte counterpart to string.containsBytes, which checks for membership in a whole byte map instead of one exact value.
| Name | Type | Description |
|---|---|---|
str | string | The string to check. |
byte | integer | The byte value to check for. |
start_positionoptional | integer | The position to start checking from, inclusive. Negative values count from the end of the string. Defaults to 1 (the start of the string). |
end_positionoptional | integer | The position to stop checking at, inclusive. Negative values count from the end of the string. Defaults to the end of the string. |
| Type | Name | Description |
|---|---|---|
boolean | has_byte | true if byte occurs anywhere within the range, false otherwise. |
#string.containsBytes
function string.containsBytes(str: string, byte_map: table<integer, boolean>, start_position?: integer, end_position?: integer): boolean, integer?, byte?
Checks whether a string contains at least one byte that's a member of the given byte map, within the given range.
byte_map is a lookup table of the kind produced by string.byteMap — a table mapping byte values to true — so this is effectively "does any byte in this range belong to the given character class".
The scan stops at the first match. If the resolved start position is greater than the end position, the range is scanned backwards, so the match returned is the last one in the string rather than the first.
| Name | Type | Description |
|---|---|---|
str | string | The string to check. |
byte_map | table<integer, boolean> | A byte map, as produced by string.byteMap, giving the set of bytes to look for. |
start_positionoptional | integer | The position to start checking from, inclusive. Negative values count from the end of the string. Defaults to 1 (the start of the string). |
end_positionoptional | integer | The position to stop checking at, inclusive. Negative values count from the end of the string. Defaults to the end of the string. |
| Type | Name | Description |
|---|---|---|
boolean | has_byte | true if any byte in the range is present in byte_map, false otherwise. |
integer? | position | The position of the first matching byte found in scan order, or nil if there is no match. |
byte? | found_byte | The value of the matching byte, or nil if there is no match. |
#string.count
function string.count(str: string, searchable: string, with_pattern?: boolean): integer
Returns the number of non-overlapping matches of a substring or pattern within a string.
Matching proceeds left to right, always resuming immediately after the end of the previous match — so overlapping occurrences are not counted separately (e.g. counting "aa" in "aaaa" returns 2, not 3).
If searchable is nil or an empty string, the length of str is returned instead of a match count, since an empty pattern would otherwise match at every position.
| Name | Type | Description |
|---|---|---|
str | string | The string to count. |
searchable | string | The substring or pattern to count by. |
with_patternoptional | boolean | When true, searchable is interpreted as a Lua pattern. Defaults to false (plain match). |
| Type | Name | Description |
|---|---|---|
integer | match_count | The number of non-overlapping matches, or string.len( str ) if searchable is nil or empty. |
#string.countByte
function string.countByte(str: string, counted_byte?: integer, reverse_direction?: boolean, start_position?: integer, end_position?: integer): integer
Returns the total number of occurrences of the specified byte within a string, scanning the whole [start_position, end_position] range rather than stopping at the first non-matching byte.
Unlike string.countConsecutiveByte, a non-matching byte doesn't end the count early — every matching byte in the range is counted, regardless of what's in between.
Returns 0 if str is empty or counted_byte is nil.
| Name | Type | Description |
|---|---|---|
str | string | The string to count. |
counted_byteoptional | integer | The byte value to count occurrences of. If nil, 0 is returned. |
reverse_directionoptional | boolean | If false, scanning goes from start_position towards higher indices (left to right). If true, scanning goes from start_position towards lower indices (right to left). Defaults to false. |
start_positionoptional | integer | The position to start counting from. Negative values count from the end of the string. Defaults to 1 when scanning forward, or the end of the string when scanning in reverse. |
end_positionoptional | integer | The position to stop counting at, inclusive. Negative values count from the end of the string. Defaults to the end of the string when scanning forward, or 1 when scanning in reverse. |
| Type | Name | Description |
|---|---|---|
integer | byte_count | The total number of occurrences of counted_byte within the range. |
#string.countConsecutiveByte
function string.countConsecutiveByte(str: string, counted_byte?: integer, reverse_direction?: boolean, start_position?: integer, end_position?: integer): integer
Returns the number of consecutive repetitions of the specified byte, starting from start_position and scanning towards end_position, stopping as soon as a byte that doesn't match counted_byte is encountered.
Note that this only counts a run starting exactly at start_position — it does not search the range for the longest run of counted_byte anywhere within it. If the byte at start_position doesn't match counted_byte, 0 is returned immediately.
Returns 0 if str is empty or counted_byte is nil.
| Name | Type | Description |
|---|---|---|
str | string | The string to count. |
counted_byteoptional | integer | The byte value to count consecutive repetitions of. If nil, 0 is returned. |
reverse_directionoptional | boolean | If false, scanning goes from start_position towards higher indices (left to right). If true, scanning goes from start_position towards lower indices (right to left). Defaults to false. |
start_positionoptional | integer | The position to start counting from. Negative values count from the end of the string. Defaults to 1 when scanning forward, or the end of the string when scanning in reverse. |
end_positionoptional | integer | The position to stop counting at, inclusive; counting stops early regardless if a non-matching byte is found first. Negative values count from the end of the string. Defaults to the end of the string when scanning forward, or 1 when scanning in reverse. |
| Type | Name | Description |
|---|---|---|
integer | byte_count | The number of consecutive occurrences of counted_byte found, starting at start_position. |
#string.diff
function string.diff(source: string, target: string, minimal?: boolean): string.Difference[], integer
Computes a Myers diff between two strings.
The result is a list of edit operations that transform source into target. Operations are returned in order from the start of the strings to the end, and runs of the same kind are merged; within every changed region removals come before insertions.
Common prefixes and suffixes shared by source and target are detected and emitted as 0 (equal) operations directly, without going through the general diff algorithm; the remaining differing middle section, if any, is solved using an O(ND) Myers shortest-edit-script search to find the minimal set of insertions and removals.
By default the minimal script is then cleaned up for readability: every equal run that is not longer than the changes on both of its sides is folded into them, so a heavily rewritten region becomes one removal and one insertion instead of a byte-by-byte mix of coincidental matches. Pass minimal as true to skip this and get the raw script.
| Name | Type | Description |
|---|---|---|
source | string | The source string. |
target | string | The target string. |
minimaloptional | boolean | If true, returns the minimal edit script without the readability cleanup. Defaults to false. |
| Type | Name | Description |
|---|---|---|
string.Difference[] | diff_ops | The difference operations. |
integer | diff_op_count | The count of difference operations. |
#string.divide
function string.divide(str: string, size?: integer): string[], integer
Splits a string into fixed-size chunks of size bytes each, in order from the start of the string. The final chunk may be shorter than size if the string's length isn't an exact multiple of it.
size is clamped to [1, string length], so it can never be 0 or negative, and a size larger than the string just returns the whole string as a single chunk.
| Name | Type | Description |
|---|---|---|
str | string | The string to split. |
sizeoptional | integer | The size, in bytes, of each segment. Defaults to 1 (split into individual bytes). Clamped to [1, #str]. |
| Type | Name | Description |
|---|---|---|
string[] | segments | The array of fixed-size segments. |
integer | segment_count | The number of segments. |
#string.escape
function string.escape(str: string, escape_spaces?: boolean, start_position?: integer, end_position?: integer): string
Escapes special characters in a string.
Within the given range, any byte that has a known escape sequence (e.g. newline, tab, quote, backslash etc.) is replaced with that sequence.
Any other byte that is a control character (below 0x20, or below 0x21 i.e. including the space character when escape_spaces is true) or is outside the printable ASCII range (0x7F and above) is replaced with a \xHH hexadecimal escape.
All other bytes, and anything outside start_position/end_position, are left untouched.
| Name | Type | Description |
|---|---|---|
str | string | The string to escape. |
escape_spacesoptional | boolean | Whether the space character (0x20) should also be escaped as \x20. Defaults to false. |
start_positionoptional | integer | The position to start escaping from, inclusive. Negative values count from the end of the string. Defaults to 1 (the start of the string). |
end_positionoptional | integer | The position to stop escaping at, inclusive. Negative values count from the end of the string. Defaults to the end of the string. |
| Type | Name | Description |
|---|---|---|
string | escaped_str | The string with special characters escaped. |
#string.escapePattern
function string.escapePattern(str: string, start_position?: integer, end_position?: integer): string
Escapes a string so it can be safely embedded in a Lua pattern and matched literally, rather than having its characters interpreted as pattern syntax.
Within the given range, every byte that has a special meaning in Lua patterns (the magic characters, listed in pattern_bytes) is prefixed with %; the null byte (0x00) is specifically escaped as %z, since patterns can't contain a literal embedded null. All other bytes, and anything outside start_position/end_position, are left untouched.
This is the pattern-syntax counterpart to string.escape, which escapes for display/ string-literal purposes rather than for safe use inside a pattern.
| Name | Type | Description |
|---|---|---|
str | string | The string to escape. |
start_positionoptional | integer | The position to start escaping from, inclusive. Negative values count from the end of the string. Defaults to 1 (the start of the string). |
end_positionoptional | integer | The position to stop escaping at, inclusive. Negative values count from the end of the string. Defaults to the end of the string. |
| Type | Name | Description |
|---|---|---|
string | escaped_str | The string with pattern-magic characters escaped for literal matching. |
#string.extract
function string.extract(str: string, searchable: string, start_position?: integer, default: string | nil, with_pattern?: boolean): string, string | nil
Finds the first match of searchable within str, removes it from the string, and returns both the remaining string and the matched text (or a capture of it, when searchable is a pattern with captures).
If searchable is a pattern (with_pattern == true) and it contains a capture, the first captured value is returned as extracted instead of the whole match; otherwise the whole matched substring is returned. If no match is found, str is returned unchanged along with default.
| Name | Type | Description |
|---|---|---|
str | string | The string to extract from. |
searchable | string | The substring or pattern to find and remove. |
start_positionoptional | integer | The position to start searching from. Defaults to 1 (the start of the string). |
default | string | nil | The value returned as extracted if no match is found. Defaults to nil. |
with_patternoptional | boolean | When true, searchable is interpreted as a Lua pattern. Defaults to false (plain match). |
| Type | Name | Description |
|---|---|---|
string | new_string | The string with the matched portion removed, or str unchanged if nothing matched. |
string | nil | extracted | The matched text (or its first capture, for patterns with captures), or default if nothing matched. |
#string.findByte
function string.findByte(str: string, searchable_byte: integer, start_position?: integer, end_position?: integer): integer | nil
Finds the position of the first occurrence of the specified byte value within a string, searching the given range.
Unlike string.find, this matches a raw byte value directly rather than a substring or pattern, so it's a cheaper option when you only need to locate one specific byte.
| Name | Type | Description |
|---|---|---|
str | string | The string to search in. |
searchable_byte | integer | The byte value to search for. |
start_positionoptional | integer | The position to start searching from, inclusive. Negative values count from the end of the string. Defaults to 1 (the start of the string). |
end_positionoptional | integer | The position to stop searching at, inclusive. Negative values count from the end of the string. Defaults to the end of the string. |
| Type | Name | Description |
|---|---|---|
integer | nil | index | The index of the first matching byte within the range, or nil if not found. |
#string.fnv0
function string.fnv0(str: string): integer
Returns the Fowler-Noll-Vo (FNV-0) [deprecated] hash of the string.
| Name | Type | Description |
|---|---|---|
str | string | The string used to calculate the Fowler-Noll-Vo hash. |
| Type | Name | Description |
|---|---|---|
integer | hash_int | The Fowler-Noll-Vo hash, which is greater or equal to 0, and less than 2^32 (0x100000000). |
#string.fnv1
function string.fnv1(str: string): integer
Returns the Fowler-Noll-Vo (FNV-1) hash of the string.
| Name | Type | Description |
|---|---|---|
str | string | The string used to calculate the Fowler-Noll-Vo hash. |
| Type | Name | Description |
|---|---|---|
integer | hash_int | The Fowler-Noll-Vo hash, which is greater or equal to 0, and less than 2^32 (0x100000000). |
#string.fnv1a
function string.fnv1a(str: string): integer
Returns the Fowler-Noll-Vo (FNV-1a) hash of the string.
| Name | Type | Description |
|---|---|---|
str | string | The string used to calculate the Fowler-Noll-Vo hash. |
| Type | Name | Description |
|---|---|---|
integer | hash_int | The Fowler-Noll-Vo hash, which is greater or equal to 0, and less than 2^32 (0x100000000). |
#string.hasPrefix
function string.hasPrefix(str: string, prefix: string, offset?: integer): boolean
Checks if the string starts with the prefix, optionally checking at a byte offset into the string rather than from the very start.
| Name | Type | Description |
|---|---|---|
str | string | The string to check. |
prefix | string | The prefix to check for. |
offsetoptional | integer | The number of bytes to skip from the start of str before checking. Defaults to 0. |
| Type | Name | Description |
|---|---|---|
boolean | has_prefix | true if the string starts with the prefix (at the given offset), false otherwise. |
#string.hasSuffix
function string.hasSuffix(str: string, suffix: string, offset?: integer): boolean
Checks if the string ends with the suffix, optionally checking with a byte offset from the end of the string rather than at the very end.
| Name | Type | Description |
|---|---|---|
str | string | The string to check. |
suffix | string | The suffix to check for. |
offsetoptional | integer | The number of bytes to ignore at the end of str before checking. Defaults to 0. |
| Type | Name | Description |
|---|---|---|
boolean | has_suffix | true if the string ends with the suffix (at the given offset), false otherwise. |
#string.indent
function string.indent(str: string, size: integer): string
Sets a string's leading indentation to exactly size spaces, replacing any existing leading whitespace rather than adding to it.
Operates on str as a single line — any existing leading whitespace is stripped (via unIndent) and then size spaces are prepended; embedded newlines are not treated specially, so only the very start of str is affected. See string.indentLines for per-line indentation of multi-line text.
| Name | Type | Description |
|---|---|---|
str | string | The string to indent. |
size | integer | The number of spaces the result should start with. |
| Type | Name | Description |
|---|---|---|
string | indented | The string with its leading whitespace replaced by size spaces. |
#string.indentLines
function string.indentLines(str: string, size: integer): string
Indents every line of a string by setting each line's leading whitespace to exactly size spaces (via string.indent), splitting on \n and rejoining the result the same way.
Like string.indent, this replaces each line's existing leading whitespace rather than adding to it.
| Name | Type | Description |
|---|---|---|
str | string | The string to indent. |
size | integer | The number of spaces each line should start with. |
| Type | Name | Description |
|---|---|---|
string | indented | The string with every line re-indented to size spaces. |
#string.indexOf
function string.indexOf(str: string, searchable: string, position?: integer, with_pattern?: boolean): integer
Returns the index of the first occurrence of searchable within str, searching from position onwards.
Returns 0 if searchable is nil or an empty string, and -1 if searchable is not found (including when position is already past the end of str) — so a non-negative result other than 0 always indicates an actual match position, while -1 specifically means "not found" and 0 specifically means "nothing to search for".
| Name | Type | Description |
|---|---|---|
str | string | The string to search in. |
searchable | string | The substring or pattern to search for. |
positionoptional | integer | The position to start searching from, inclusive. Negative values count from the end of the string. Defaults to 1 (the start of the string). |
with_patternoptional | boolean | When true, searchable is interpreted as a Lua pattern. Defaults to false (plain match). |
| Type | Name | Description |
|---|---|---|
integer | index | The index of the first match, 0 if searchable is nil or empty, or -1 if no match is found. |
#string.insert
function string.insert(str: string, index: integer, value: string): string
Inserts value into str at the given index, shifting everything from index onwards to the right.
index defaults to the end of the string (i.e. appending), and negative values count from the end of the string. An index of 0 inserts before the first character, and an index beyond the string's length is clamped to appending at the end.
When called with only two arguments (string.insert( str, value )), value is simply appended to the end of str.
| Name | Type | Description |
|---|---|---|
str | string | The string to insert into. |
index | integer | The position to insert at. Defaults to the end of the string; negative values count from the end. |
value | string | The string value to insert. |
| Type | Name | Description |
|---|---|---|
string | result | The string with value inserted at the given position. |
function string.insert(str: string, value: string): string
#string.interpolate
function string.interpolate(str: string, variables: string[] | table<string, string>, start_position?: integer, end_position?: integer): string
Interpolates a string with the given arguments, replacing {...} placeholders with values from variables, within the given range.
The arguments are replaced in the string using the following format:
{1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}
It's also supports named arguments:
{key}, {my_val}, {something} and etc.
In both cases the text between the braces is used as a literal string key into variables (so {1} looks up variables["1"], not variables[1]) — keep that in mind when passing a positional/array-style table, since Lua treats numeric and string keys as distinct.
A backslash (\) escapes the character immediately following it, both inside and outside of {...}, so e.g. \{ or \} can be used to include a literal brace without it being treated as a placeholder delimiter.
A placeholder is only replaced if its key exists in variables with a non-nil value; otherwise the placeholder (including its braces) is left in the output unchanged. The same applies to an empty placeholder ({}) and to an unterminated { with no matching } before end_position — both are left as literal text rather than erroring.
| Name | Type | Description |
|---|---|---|
str | string | The string to interpolate. |
variables | string[] | table<string, string> | The replacement values, keyed by the literal text inside each {...} placeholder (as a string key, even for numeric-looking placeholders like {1}). |
start_positionoptional | integer | The position to start interpolating from, inclusive. Negative values count from the end of the string. Defaults to 1 (the start of the string). Text before this position is copied through unchanged. |
end_positionoptional | integer | The position to stop interpolating at, inclusive. Negative values count from the end of the string. Defaults to the end of the string. Text after this position is copied through unchanged. |
| Type | Name | Description |
|---|---|---|
string | str | The interpolated string. |
string.format
#string.interpolateByte
function string.interpolateByte(str: string, interpolate_byte: integer, variables: string[], variable_count?: integer, start_position?: integer, end_position?: integer): string
Replaces occurrences of a specific byte in the string with values from variables, in the order they're found — the first occurrence of interpolate_byte is replaced with variables[1], the second with variables[2], and so on.
Unlike string.interpolate, which matches named/numbered {...} placeholders, this matches a single repeated placeholder byte (similar to %s-style sequential substitution, but using one literal byte as the marker instead of a format specifier). It also has no escape syntax — every occurrence of interpolate_byte within the range is treated as a placeholder, with no way to include a literal copy of that byte.
Substitution stops once every entry in variables (up to variable_count) has been used; any further occurrences of interpolate_byte beyond that point are left untouched in the output. If variable_count is 0 (or variables is empty), the string is returned unchanged without scanning it at all.
| Name | Type | Description |
|---|---|---|
str | string | The string to interpolate. |
interpolate_byte | integer | The byte value that acts as a placeholder marker. |
variables | string[] | The replacement values, used in order of occurrence within the string. |
variable_countoptional | integer | The number of entries in variables to use. Defaults to #variables (via len); pass this to skip that calculation when the count is already known. |
start_positionoptional | integer | The position to start interpolating from, inclusive. Negative values count from the end of the string. Defaults to 1 (the start of the string). Text before this position is copied through unchanged. |
end_positionoptional | integer | The position to stop interpolating at, inclusive. Negative values count from the end of the string. Defaults to the end of the string. Text after this position is copied through unchanged. |
| Type | Name | Description |
|---|---|---|
string | str | The interpolated string. |
#string.isBytecode
function string.isBytecode(str: string, jit_version: `0x01` | `0x02` | integer, start_position?: integer): boolean
Checks whether a string starts with a LuaJIT bytecode header for the given JIT version.
Verifies that the first three bytes at start_position match the LuaJIT bytecode magic signature \x1BLJ (ESC, L, J), and that the fourth byte equals jit_version — this is the same version byte exposed as jit.version_byte (e.g. 0x01 for LuaJIT 2.0, 0x02 for LuaJIT 2.1), which lets a loader reject bytecode compiled for a different LuaJIT version before attempting to load it.
This only checks the header; it doesn't validate the rest of the chunk as well-formed bytecode.
| Name | Type | Description |
|---|---|---|
str | string | The string to check. |
jit_version | `0x01` | `0x02` | integer | The expected LuaJIT bytecode version byte to match against (see jit.version_byte). |
start_positionoptional | integer | The position in str where the bytecode header is expected to start. Defaults to 1 (the start of the string). |
| Type | Name | Description |
|---|---|---|
boolean | result | true if str starts with a matching LuaJIT bytecode header at start_position, false otherwise. |
#string.isEmpty
function string.isEmpty(str: string): boolean
Checks whether a string is empty, i.e. has no bytes at all.
| Name | Type | Description |
|---|---|---|
str | string | The string to check. |
| Type | Name | Description |
|---|---|---|
boolean | result | true if str has zero length, false otherwise. |
#string.isNumber
function string.isNumber(str: string, base?: integer, start_position?: integer, end_position?: integer): boolean
Checks whether a string (or a sub-range of it) can be parsed as a valid number, using the same base auto-detection and sub-range rules as toNumber/string.toNumber.
Equivalent to string.toNumber( str, base, start_position, end_position ) ~= nil, but without needing to hold on to the converted value when only the validity check matters.
| Name | Type | Description |
|---|---|---|
str | string | The string to check. |
baseoptional | integer | The numeric base to check str in. If omitted, the base is auto-detected from the string's prefix (0x/0X → 16, leading 0 → 8, otherwise 10). |
start_positionoptional | integer | The position to start checking from. Defaults to 1 (the start of the string). |
end_positionoptional | integer | The position to stop checking at. Defaults to the end of the string. |
| Type | Name | Description |
|---|---|---|
boolean | is_number | true if the (sub)string is a valid number in the given base, false otherwise. |
#string.isURL
function string.isURL(str: string): boolean
Checks whether a string looks like a well-formed URL, matched against a strict pattern rather than resolved or validated against any real scheme or host.
Specifically requires: a scheme starting with a lowercase letter and continuing with lowercase letters, +, -, or . (e.g. http, git+ssh), followed by a :, followed by the rest of the URL — which may be empty, but must not contain whitespace or control characters (bytes 0x00–0x20), bytes above 0x7E (0x7F–0xFF), or the characters ", <, >, ^, ` `, {, |, or }`.
This is a syntactic sanity check, not a full RFC 3986 validator — it doesn't verify that the scheme is a known/registered one, or inspect the structure of the authority, path, query, or fragment beyond the character restrictions above.
| Name | Type | Description |
|---|---|---|
str | string | The string to check. |
| Type | Name | Description |
|---|---|---|
boolean | result | true if str matches the expected URL shape, false otherwise. |
#string.pack
function string.pack(bytes: integer[], byte_count?: integer): string
Packs a sequence of bytes into a string, the inverse of string.unpack.
Equivalent to string.char( table.unpack( bytes, 1, byte_count ) ), but built with string_char calls batched 32 bytes at a time for performance rather than unpacking the whole array (and hitting Lua's C-stack argument limit) in one call.
| Name | Type | Description |
|---|---|---|
bytes | integer[] | The sequence of bytes to pack, each an integer in the range 0-255. |
byte_countoptional | integer | The number of bytes, from the start of bytes, to pack. Defaults to len( bytes ) (the whole array). |
| Type | Name | Description |
|---|---|---|
string | str | The packed byte string. |
#string.pad
function string.pad(str: string, desired_length: integer, padding?: string, left?: boolean, right?: boolean): string
Pads a string with a repeated padding string until it reaches desired_length characters, on the left, the right, or both sides evenly.
If neither left nor right is true, or the string is already at least desired_length characters long, str is returned unchanged.
When padding both sides, the missing length is split as evenly as possible between the left and right; if it doesn't divide evenly by whole copies of padding, the shortfall is made up with a partial copy of padding, with any extra leftover character going to the right side.
This is the byte-length counterpart to unicode.pad, which measures and pads by display width (columns) instead of raw byte length.
| Name | Type | Description |
|---|---|---|
str | string | The string to pad. |
desired_length | integer | The target length, in bytes, that the result should reach. |
paddingoptional | string | The string to pad with, repeated as needed. Defaults to a single space. |
leftoptional | boolean | Whether to add padding on the left side. |
rightoptional | boolean | Whether to add padding on the right side. |
| Type | Name | Description |
|---|---|---|
string | padded_str | The padded string, or str unchanged if no padding was needed or requested. |
#string.purge
function string.purge(str: string, byte: integer, start_position?: integer, end_position?: integer): string
Removes every occurrence of the specified byte from a string, within the given range.
Implemented by splitting str around every occurrence of byte (via byte_split) and rejoining the pieces with nothing in between — equivalent to string.byteReplace( str, byte, "", start_position, end_position ), but without the overhead of an optional replacement argument.
| Name | Type | Description |
|---|---|---|
str | string | The string to purge. |
byte | integer | The byte value to remove. |
start_positionoptional | integer | The position to start purging from, inclusive. Bytes outside this range are left untouched. |
end_positionoptional | integer | The position to stop purging at, inclusive. Bytes outside this range are left untouched. |
| Type | Name | Description |
|---|---|---|
string | str_purged | The string with every occurrence of byte removed. |
#string.quote
function string.quote(str: string, use_single?: boolean): string
Wraps a string in quotes, escaping any quote characters of the same kind already inside it so the result is a syntactically valid quoted literal.
Only the quote character itself is escaped — other characters that would normally need escaping in a string literal (backslashes, newlines, etc.) are left untouched, so this is not a full string-literal encoder, just a quote-wrapping helper.
Inverse of string.unQuote.
| Name | Type | Description |
|---|---|---|
str | string | The string to quote. |
use_singleoptional | boolean | When true, wraps in single quotes (') and escapes any ' inside str. When false/omitted, wraps in double quotes (") and escapes any " inside str. |
| Type | Name | Description |
|---|---|---|
string | result | The quoted string. |
#string.random
function string.random(length?: integer, lowercase?: boolean, uppercase?: boolean, numbers?: boolean, symbols?: boolean, extended_ascii?: boolean): string
Generates a random string by repeatedly picking a random character pool and then a random character from it.
Can be used to generate a password/key/secret.
lowercase and numbers are included by default; uppercase, symbols, and extended_ascii are opt-in. At each position, one of the enabled pools is chosen at random with equal probability per pool, not per character — so if one pool is much larger than another (e.g. extended_ascii vs numbers), characters from the smaller pool still appear just as often on average, rather than being proportionally under-represented.
The length of the string is 8 by default. Passing 0 returns an empty string without requiring any pool to be enabled.
| Name | Type | Description |
|---|---|---|
lengthoptional | integer | The length of the string, defaults to 8. |
lowercaseoptional | boolean | Whether to include lowercase letters (a-z). Defaults to true. |
uppercaseoptional | boolean | Whether to include uppercase letters (A-Z). Defaults to false. |
numbersoptional | boolean | Whether to include digits (0-9). Defaults to true. |
symbolsoptional | boolean | Whether to include symbol/punctuation characters. Defaults to false. |
extended_asciioptional | boolean | Whether to include extended (non-ASCII, above 0x7F) characters. Defaults to false. |
| Type | Name | Description |
|---|---|---|
string | result | A randomly generated string of the requested length, drawn from the enabled character pools. |
#string.remove
function string.remove(str: string, start_position: integer, end_position: integer): string
Removes the inclusive byte range [start_position, end_position] from a string, returning what remains with the gap closed up.
If the range covers the entire string, an empty string is returned.
| Name | Type | Description |
|---|---|---|
str | string | The string to remove from. |
start_position | integer | The start position of the removal interval, inclusive. Negative values count from the end of the string. Defaults to 1 (the start of the string). |
end_position | integer | The end position of the removal interval, inclusive. Negative values count from the end of the string. Defaults to the end of the string. |
| Type | Name | Description |
|---|---|---|
string | new_string | The string with the specified byte interval removed. |
#string.replace
function string.replace(str: string, searchable?: string, replaceable?: string, with_pattern?: boolean, start_position?: integer, end_position?: integer): string
Replaces all occurrences of searchable within str with replaceable.
Implemented by splitting str around every match of searchable (within the given range) and rejoining the pieces with replaceable in between — so this behaves the same as split( str, searchable, with_pattern, start_position, end_position ) followed by table.concat( segments, replaceable ). If searchable doesn't occur in str (or in the given range), the string is returned unchanged.
| Name | Type | Description |
|---|---|---|
str | string | The string we are seeking to replace an occurrence(s) in. |
searchableoptional | string | What we are seeking to replace, or the substring or pattern to split by. |
replaceableoptional | string | What to replace it with. If nil, occurrences are removed. |
with_patternoptional | boolean | When true, searchable is interpreted as a Lua pattern. Defaults to false (plain match). |
start_positionoptional | integer | The position to start replacing from, inclusive. Matches outside this range are left untouched. |
end_positionoptional | integer | The position to stop replacing at, inclusive. Matches outside this range are left untouched. |
| Type | Name | Description |
|---|---|---|
string | str_replaced | The new string with the occurrences replaced. |
#string.split
function string.split(str: string, searchable?: string, with_pattern?: boolean, start_position?: integer, end_position?: integer): string[], integer
Splits a string into an array of substrings around every occurrence of searchable within the given range. The matched delimiter itself is not included in any segment.
If searchable is nil or an empty string, the string is instead split into one segment per byte (effectively str_length single-character segments), ignoring with_pattern, start_position, and end_position entirely.
Consecutive delimiters, or a delimiter at the very start or end of the searched range, produce empty-string segments rather than being collapsed or skipped — the segment count is always exactly one more than the number of delimiter matches found. If searchable never occurs within the range, the whole range is returned as a single segment.
string.replace is built directly on top of this function, rejoining the returned segments with a replacement string in place of replaceable.
| Name | Type | Description |
|---|---|---|
str | string | The string to split. |
searchableoptional | string | The substring or pattern to split by. If nil or empty, splits into individual bytes instead. |
with_patternoptional | boolean | When true, searchable is interpreted as a Lua pattern. Defaults to false (plain match). |
start_positionoptional | integer | The position to start splitting from, inclusive. Negative values count from the end of the string. Defaults to 1 (the start of the string). Ignored if searchable is nil or empty. |
end_positionoptional | integer | The position to stop splitting at, inclusive. Negative values count from the end of the string. Defaults to the end of the string. Ignored if searchable is nil or empty. |
| Type | Name | Description |
|---|---|---|
string[] | segments | The resulting array of substrings. |
integer | segment_count | The number of entries in segments. |
#string.toNumber
function string.toNumber(str: string, base?: integer, start_position?: integer, end_position?: integer): number | nil
Converts a string, or a sub-range of it, to a number, with automatic base detection when base is omitted.
If base is nil, the start of the (sub)string is inspected to guess the base: a 0x/ 0X prefix selects base 16, a leading 0 followed by another digit selects base 8, and anything else defaults to base 10. A bare "0x"/"0X" prefix with nothing after it is treated as a literal 0 rather than being passed through to the underlying conversion.
If neither start_position nor end_position is given, the whole string is converted directly; otherwise the selected sub-range is extracted first (via string.sub semantics) and that substring is converted instead.
| Name | Type | Description |
|---|---|---|
str | string | The string to convert. |
baseoptional | integer | The numeric base to interpret str in. If omitted, the base is auto-detected from the string's prefix (0x/0X → 16, leading 0 → 8, otherwise 10). |
start_positionoptional | integer | The position to start converting from. Defaults to 1 (the start of the string). |
end_positionoptional | integer | The position to stop converting at. Defaults to the end of the string. |
| Type | Name | Description |
|---|---|---|
number | nil | num | The converted number, or nil if the (sub)string is not a valid number in the given base. |
#string.trim
function string.trim(str: string, pattern_str?: string, left?: boolean, right?: boolean): string
Removes leading and/or trailing matches of a character set from a string.
pattern_str is treated as a set of characters to trim, not a general Lua pattern: a single character is escaped via pattern_bytes (if needed) and matched literally; a multi-character string that isn't already a %-class (like %s) is wrapped as a character class ([...]), so e.g. "-_" trims any run of - and _ characters, not the literal substring "-_". Defaults to %s (whitespace) when omitted.
left and right both default to true; passing false for either one disables trimming on that side while leaving the other side's default behavior unchanged, so only an explicit false turns a side off.
| Name | Type | Description |
|---|---|---|
str | string | The string to trim. |
pattern_stroptional | string | The set of characters to trim, as a single character, a %-class, or a run of characters to treat as a class. Defaults to %s (whitespace). |
leftoptional | boolean | Whether to trim from the start of the string. Defaults to true. |
rightoptional | boolean | Whether to trim from the end of the string. Defaults to true. |
| Type | Name | Description |
|---|---|---|
string | trimmed_str | The trimmed string. |
#string.trimByte
function string.trimByte(str: string, trailing_byte?: integer, left?: boolean, right?: boolean, start_position?: integer, end_position?: integer): string, integer
Removes leading and/or trailing occurrences of a single specific byte from a string, within the given range.
Unlike string.trim, this matches one exact byte value rather than a Lua pattern or character class — it's a cheaper, byte-level equivalent for the common case of trimming a single fixed character (e.g. spaces, null bytes, a delimiter).
left and right both default to true; passing false for either one disables trimming on that side while leaving the other side's default behavior unchanged.
If the entire range consists of trailing_byte, the result is an empty string.
| Name | Type | Description |
|---|---|---|
str | string | The string to trim. |
trailing_byteoptional | integer | The byte value to trim from the start and/or end. Defaults to 0x20 (space). |
leftoptional | boolean | Whether to trim from the start of the string. Defaults to true. |
rightoptional | boolean | Whether to trim from the end of the string. Defaults to true. |
start_positionoptional | integer | The position to start trimming within, inclusive. Negative values count from the end of the string. Defaults to 1 (the start of the string). |
end_positionoptional | integer | The position to stop trimming within, inclusive. Negative values count from the end of the string. Defaults to the end of the string. |
| Type | Name | Description |
|---|---|---|
string | trimmed_str | The trimmed string. |
integer | trimmed_length | The length of the trimmed string. |
#string.trimSpaces
function string.trimSpaces(str: string, left?: boolean, right?: boolean, start_position?: integer, end_position?: integer): string, integer
Removes leading and/or trailing whitespace characters from a string, within the given range, and returns the trimmed string along with its length.
A byte counts as whitespace according to ascii_isSpace (space, tab, newline, and other ASCII whitespace bytes), not just the literal space character — unlike string.trimByte, which only matches one specific byte value.
left and right both default to true; passing false for either one disables trimming on that side while leaving the other side's default behavior unchanged.
If the entire range consists of whitespace, the result is an empty string.
| Name | Type | Description |
|---|---|---|
str | string | The string to trim. |
leftoptional | boolean | Whether to trim from the start of the string. Defaults to true. |
rightoptional | boolean | Whether to trim from the end of the string. Defaults to true. |
start_positionoptional | integer | The position to start trimming within, inclusive. Negative values count from the end of the string. Defaults to 1 (the start of the string). |
end_positionoptional | integer | The position to stop trimming within, inclusive. Negative values count from the end of the string. Defaults to the end of the string. |
| Type | Name | Description |
|---|---|---|
string | trimmed_str | The trimmed string. |
integer | trimmed_length | The length of the trimmed string. |
#string.unescape
function string.unescape(escaped_str: string, start_position?: integer, end_position?: integer): string
Unescapes special characters in a string.
The inverse of string.escape.
Within the given range, recognized escape sequences (e.g. \n, \t, \", \\ etc.) are converted back into their raw byte, and \xHH hexadecimal escapes are decoded into the byte they represent.
Any other byte, and anything outside start_position/end_position, is left untouched.
| Name | Type | Description |
|---|---|---|
escaped_str | string | The string to unescape. |
start_positionoptional | integer | The position to start unescaping from, inclusive. Negative values count from the end of the string. Defaults to 1 (the start of the string). |
end_positionoptional | integer | The position to stop unescaping at, inclusive. Negative values count from the end of the string. Defaults to the end of the string. |
| Type | Name | Description |
|---|---|---|
string | str | The unescaped string. |
#string.unIndent
function string.unIndent(str: string, size?: integer): string
Removes leading whitespace from the start of a single-line string (does not affect subsequent lines if str contains embedded newlines — see string.unindentLines for that).
If size is given, at most size leading whitespace bytes are removed; otherwise all leading whitespace is removed, equivalent to string.trimSpaces( str, true, false ).
| Name | Type | Description |
|---|---|---|
str | string | The string to unindent. |
sizeoptional | integer | The maximum number of leading whitespace bytes to remove. Defaults to removing all of them. |
| Type | Name | Description |
|---|---|---|
string | unindented | The string with leading whitespace removed. |
#string.unindentLines
function string.unindentLines(str: string, size?: integer): string
Removes leading whitespace from every line of a string (via string.unIndent), splitting on \n and rejoining the result the same way. The multi-line counterpart to string.unIndent, which only strips the first line.
| Name | Type | Description |
|---|---|---|
str | string | The string to unindent. |
sizeoptional | integer | The maximum number of leading whitespace bytes to remove from each line. Defaults to removing all of them. |
| Type | Name | Description |
|---|---|---|
string | unindented | The string with leading whitespace removed from every line. |
#string.unpack
function string.unpack(str: string, start_position?: integer, end_position?: integer): integer[], integer
Unpacks a string into a sequence of bytes, the inverse of string.pack.
Equivalent to { string.byte( str, start_position, end_position ) } over the given range, but built with string_byte calls batched 32 bytes at a time for performance.
| Name | Type | Description |
|---|---|---|
str | string | The string to unpack. |
start_positionoptional | integer | The position to start unpacking from, inclusive. Negative values count from the end of the string. Defaults to 1 (the start of the string). |
end_positionoptional | integer | The position to stop unpacking at, inclusive. Negative values count from the end of the string. Defaults to the end of the string (string.len( str )). |
| Type | Name | Description |
|---|---|---|
integer[] | bytes | The unpacked bytes, one entry per byte in the range. |
integer | byte_count | The number of bytes unpacked (i.e. #bytes). |
#string.unQuote
function string.unQuote(str: string, use_single?: boolean): string
Removes a surrounding pair of quotes from a string and unescapes any escaped quote characters of the same kind inside it. Inverse of string.quote.
If str isn't wrapped in the expected quote character at both ends, it's returned unchanged (aside from unescaping) rather than erroring — so this is safe to call on a string that may or may not actually be quoted.
| Name | Type | Description |
|---|---|---|
str | string | The string to unquote. |
use_singleoptional | boolean | When true, expects and strips single quotes (') and unescapes \' inside str. When false/omitted, expects and strips double quotes (") and unescapes \" inside str. |
| Type | Name | Description |
|---|---|---|
string | result | The unquoted string, or str unchanged (with unescaping still applied) if it wasn't wrapped in the expected quote character. |