dreamworkAPI
Ctrl K
GitHub
libraryDocs / string

string

librarysharedmenusource

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

NameTypeDescription
PatternBytestable<integer, string>A table of bytes that map to pattern sequences.
bufferstring.bufferlib | nilThe string buffer library allows high-performance manipulation of string-like data.

Functions

string.byteMapCreates a byte map — a lookup table from byte value to true — from a list of individual byte strings and/or byte ranges…
string.bytePadPads a string with a single repeated byte until it reaches desired_length characters, on the left, the right, or both s…
string.byteRepReturns a string that is the concatenation of repetitions copies of the byte rep_byte.
string.byteReplaceReplaces all occurrences of the specified byte within str with replaceable, within the given range.
string.byteSplitSplits a string into an array of substrings, breaking at every occurrence of the specified byte within the given range.
string.commaInserts a separator (e.g. a comma) every offset characters, counting from the right end of the string — the typical "th…
string.containsChecks if str contains searchable.
string.containsByteChecks whether a string contains the specified single byte value, within the given range.
string.containsBytesChecks whether a string contains at least one byte that's a member of the given byte map, within the given range.
string.countReturns the number of non-overlapping matches of a substring or pattern within a string.
string.countByteReturns the total number of occurrences of the specified byte within a string, scanning the whole [start_position, end_…
string.countConsecutiveByteReturns the number of consecutive repetitions of the specified byte, starting from start_position and scanning towards…
string.diffComputes a Myers diff between two strings.
string.divideSplits a string into fixed-size chunks of size bytes each, in order from the start of the string.
string.escapeEscapes special characters in a string.
string.escapePatternEscapes a string so it can be safely embedded in a Lua pattern and matched literally, rather than having its characters…
string.extractFinds the first match of searchable within str, removes it from the string, and returns both the remaining string and t…
string.findByteFinds the position of the first occurrence of the specified byte value within a string, searching the given range.
string.fnv0Returns the Fowler-Noll-Vo (FNV-0) [deprecated] hash of the string.
string.fnv1Returns the Fowler-Noll-Vo (FNV-1) hash of the string.
string.fnv1aReturns the Fowler-Noll-Vo (FNV-1a) hash of the string.
string.hasPrefixChecks if the string starts with the prefix, optionally checking at a byte offset into the string rather than from the…
string.hasSuffixChecks if the string ends with the suffix, optionally checking with a byte offset from the end of the string rather tha…
string.indentSets a string's leading indentation to exactly size spaces, replacing any existing leading whitespace rather than addin…
string.indentLinesIndents every line of a string by setting each line's leading whitespace to exactly size spaces (via string.indent), sp…
string.indexOfReturns the index of the first occurrence of searchable within str, searching from position onwards.
string.insertInserts value into str at the given index, shifting everything from index onwards to the right.
string.interpolateInterpolates a string with the given arguments, replacing {...} placeholders with values from variables, within the giv…
string.interpolateByteReplaces occurrences of a specific byte in the string with values from variables, in the order they're found — the firs…
string.isBytecodeChecks whether a string starts with a LuaJIT bytecode header for the given JIT version.
string.isEmptyChecks whether a string is empty, i.e. has no bytes at all.
string.isNumberChecks whether a string (or a sub-range of it) can be parsed as a valid number, using the same base auto-detection and…
string.isURLChecks whether a string looks like a well-formed URL, matched against a strict pattern rather than resolved or validate…
string.packPacks a sequence of bytes into a string, the inverse of string.unpack.
string.padPads a string with a repeated padding string until it reaches desired_length characters, on the left, the right, or bot…
string.purgeRemoves every occurrence of the specified byte from a string, within the given range.
string.quoteWraps a string in quotes, escaping any quote characters of the same kind already inside it so the result is a syntactic…
string.randomGenerates a random string by repeatedly picking a random character pool and then a random character from it.
string.removeRemoves the inclusive byte range [start_position, end_position] from a string, returning what remains with the gap clos…
string.replaceReplaces all occurrences of searchable within str with replaceable.
string.splitSplits a string into an array of substrings around every occurrence of searchable within the given range.
string.toNumberConverts a string, or a sub-range of it, to a number, with automatic base detection when base is omitted.
string.trimRemoves leading and/or trailing matches of a character set from a string.
string.trimByteRemoves leading and/or trailing occurrences of a single specific byte from a string, within the given range.
string.trimSpacesRemoves leading and/or trailing whitespace characters from a string, within the given range, and returns the trimmed st…
string.unescapeUnescapes special characters in a string.
string.unIndentRemoves leading whitespace from the start of a single-line string (does not affect subsequent lines if str contains emb…
string.unindentLinesRemoves leading whitespace from every line of a string (via string.unIndent), splitting on \n and rejoining the result…
string.unpackUnpacks a string into a sequence of bytes, the inverse of string.pack.
string.unQuoteRemoves a surrounding pair of quotes from a string and unescapes any escaped quote characters of the same kind inside i…

#string.byteMap

sharedmenunodiscardsource
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.

Parameters
NameTypeDescription
...string | string.ByteMapRangeA list of bytes or byte ranges to include in the map.
Returns
TypeNameDescription
table<integer, boolean>byte_mapA table mapping each included byte value to true.

#string.bytePad

sharedmenunodiscardsource
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.

Parameters
NameTypeDescription
strstringThe string to pad.
desired_lengthintegerThe target length, in bytes, that the result should reach.
padding_byteoptionalintegerThe byte value to pad with. Defaults to 0x20 (space).
leftoptionalbooleanWhether to add padding on the left side.
rightoptionalbooleanWhether to add padding on the right side.
Returns
TypeNameDescription
stringpadded_strThe padded string, or str unchanged if no padding was needed or requested.

#string.byteRep

sharedmenunodiscardsource
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 ).

Parameters
NameTypeDescription
rep_byteintegerThe byte value to repeat (0-255).
repetitionsoptionalintegerThe number of times to repeat the byte. Defaults to 1.
Returns
TypeNameDescription
stringrep_strThe byte repeated repetitions times, as a string.

#string.byteReplace

sharedmenunodiscardsource
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).

Parameters
NameTypeDescription
strstringThe string we are seeking to replace an occurrence(s) in.
searchable_byteoptionalintegerThe byte value to find and replace. Defaults to 0x20 (space).
replaceableoptionalstringWhat to replace each occurrence with. If nil, occurrences are removed.
start_positionoptionalintegerThe position to start replacing from, inclusive. Matches outside this range are left untouched.
end_positionoptionalintegerThe position to stop replacing at, inclusive. Matches outside this range are left untouched.
Returns
TypeNameDescription
stringstr_replacedThe new string with the occurrences replaced.

#string.byteSplit

sharedmenunodiscardsource
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" }.

Parameters
NameTypeDescription
strstringThe string to split.
searchable_byteoptionalintegerThe byte value to split on. Defaults to 0x20 (space).
start_positionoptionalintegerThe position to start splitting from, inclusive. Negative values count from the end of the string. Defaults to 1 (the start of the string).
end_positionoptionalintegerThe position to stop splitting at, inclusive. Negative values count from the end of the string. Defaults to the end of the string.
Returns
TypeNameDescription
string[]segmentsThe resulting array of substrings.
integersegment_countThe number of entries in segments.

#string.comma

sharedmenunodiscardsource
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.

Parameters
NameTypeDescription
strstringThe string to format.
separatoroptionalstringThe separator string to insert between groups. Defaults to ",".
offsetoptionalintegerThe number of characters per group, counted from the right. Defaults to 3. Normalized to a non-negative integer; 0 returns str unchanged.
Returns
TypeNameDescription
stringstrThe string with separators inserted every offset characters from the right.

#string.contains

sharedmenunodiscardsource
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.

Parameters
NameTypeDescription
strstringThe string to search in.
searchablestringThe substring or pattern to search for.
with_patternoptionalbooleanWhen true, searchable is interpreted as a Lua pattern. Defaults to false (plain match).
start_positionoptionalintegerThe byte position to start searching from. Defaults to 1. Negative values count from the end of the string.
Returns
TypeNameDescription
booleanfoundtrue if searchable was found within str, false otherwise.

#string.containsByte

sharedmenunodiscardsource
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.

Parameters
NameTypeDescription
strstringThe string to check.
byteintegerThe byte value to check for.
start_positionoptionalintegerThe position to start checking from, inclusive. Negative values count from the end of the string. Defaults to 1 (the start of the string).
end_positionoptionalintegerThe position to stop checking at, inclusive. Negative values count from the end of the string. Defaults to the end of the string.
Returns
TypeNameDescription
booleanhas_bytetrue if byte occurs anywhere within the range, false otherwise.

#string.containsBytes

sharedmenunodiscardsource
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.

Parameters
NameTypeDescription
strstringThe string to check.
byte_maptable<integer, boolean>A byte map, as produced by string.byteMap, giving the set of bytes to look for.
start_positionoptionalintegerThe position to start checking from, inclusive. Negative values count from the end of the string. Defaults to 1 (the start of the string).
end_positionoptionalintegerThe position to stop checking at, inclusive. Negative values count from the end of the string. Defaults to the end of the string.
Returns
TypeNameDescription
booleanhas_bytetrue if any byte in the range is present in byte_map, false otherwise.
integer?positionThe position of the first matching byte found in scan order, or nil if there is no match.
byte?found_byteThe value of the matching byte, or nil if there is no match.

#string.count

sharedmenunodiscardsource
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.

Parameters
NameTypeDescription
strstringThe string to count.
searchablestringThe substring or pattern to count by.
with_patternoptionalbooleanWhen true, searchable is interpreted as a Lua pattern. Defaults to false (plain match).
Returns
TypeNameDescription
integermatch_countThe number of non-overlapping matches, or string.len( str ) if searchable is nil or empty.

#string.countByte

sharedmenunodiscardsource
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.

Parameters
NameTypeDescription
strstringThe string to count.
counted_byteoptionalintegerThe byte value to count occurrences of. If nil, 0 is returned.
reverse_directionoptionalbooleanIf 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_positionoptionalintegerThe 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_positionoptionalintegerThe 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.
Returns
TypeNameDescription
integerbyte_countThe total number of occurrences of counted_byte within the range.

#string.countConsecutiveByte

sharedmenunodiscardsource
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.

Parameters
NameTypeDescription
strstringThe string to count.
counted_byteoptionalintegerThe byte value to count consecutive repetitions of. If nil, 0 is returned.
reverse_directionoptionalbooleanIf 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_positionoptionalintegerThe 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_positionoptionalintegerThe 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.
Returns
TypeNameDescription
integerbyte_countThe number of consecutive occurrences of counted_byte found, starting at start_position.

#string.diff

sharedmenunodiscardsource
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.

Parameters
NameTypeDescription
sourcestringThe source string.
targetstringThe target string.
minimaloptionalbooleanIf true, returns the minimal edit script without the readability cleanup. Defaults to false.
Returns
TypeNameDescription
string.Difference[]diff_opsThe difference operations.
integerdiff_op_countThe count of difference operations.

#string.divide

sharedmenunodiscardsource
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.

Parameters
NameTypeDescription
strstringThe string to split.
sizeoptionalintegerThe size, in bytes, of each segment. Defaults to 1 (split into individual bytes). Clamped to [1, #str].
Returns
TypeNameDescription
string[]segmentsThe array of fixed-size segments.
integersegment_countThe number of segments.

#string.escape

sharedmenunodiscardsource
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.

Parameters
NameTypeDescription
strstringThe string to escape.
escape_spacesoptionalbooleanWhether the space character (0x20) should also be escaped as \x20. Defaults to false.
start_positionoptionalintegerThe position to start escaping from, inclusive. Negative values count from the end of the string. Defaults to 1 (the start of the string).
end_positionoptionalintegerThe position to stop escaping at, inclusive. Negative values count from the end of the string. Defaults to the end of the string.
Returns
TypeNameDescription
stringescaped_strThe string with special characters escaped.
See also

#string.escapePattern

sharedmenunodiscardsource
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.

Parameters
NameTypeDescription
strstringThe string to escape.
start_positionoptionalintegerThe position to start escaping from, inclusive. Negative values count from the end of the string. Defaults to 1 (the start of the string).
end_positionoptionalintegerThe position to stop escaping at, inclusive. Negative values count from the end of the string. Defaults to the end of the string.
Returns
TypeNameDescription
stringescaped_strThe string with pattern-magic characters escaped for literal matching.

#string.extract

sharedmenunodiscardsource
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.

Parameters
NameTypeDescription
strstringThe string to extract from.
searchablestringThe substring or pattern to find and remove.
start_positionoptionalintegerThe position to start searching from. Defaults to 1 (the start of the string).
defaultstring | nilThe value returned as extracted if no match is found. Defaults to nil.
with_patternoptionalbooleanWhen true, searchable is interpreted as a Lua pattern. Defaults to false (plain match).
Returns
TypeNameDescription
stringnew_stringThe string with the matched portion removed, or str unchanged if nothing matched.
string | nilextractedThe matched text (or its first capture, for patterns with captures), or default if nothing matched.

#string.findByte

sharedmenunodiscardsource
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.

Parameters
NameTypeDescription
strstringThe string to search in.
searchable_byteintegerThe byte value to search for.
start_positionoptionalintegerThe position to start searching from, inclusive. Negative values count from the end of the string. Defaults to 1 (the start of the string).
end_positionoptionalintegerThe position to stop searching at, inclusive. Negative values count from the end of the string. Defaults to the end of the string.
Returns
TypeNameDescription
integer | nilindexThe index of the first matching byte within the range, or nil if not found.

#string.fnv0

sharedmenunodiscardsource
function string.fnv0(str: string): integer

Returns the Fowler-Noll-Vo (FNV-0) [deprecated] hash of the string.

Wiki Page

Parameters
NameTypeDescription
strstringThe string used to calculate the Fowler-Noll-Vo hash.
Returns
TypeNameDescription
integerhash_intThe Fowler-Noll-Vo hash, which is greater or equal to 0, and less than 2^32 (0x100000000).

#string.fnv1

sharedmenunodiscardsource
function string.fnv1(str: string): integer

Returns the Fowler-Noll-Vo (FNV-1) hash of the string.

Wiki Page

Parameters
NameTypeDescription
strstringThe string used to calculate the Fowler-Noll-Vo hash.
Returns
TypeNameDescription
integerhash_intThe Fowler-Noll-Vo hash, which is greater or equal to 0, and less than 2^32 (0x100000000).

#string.fnv1a

sharedmenunodiscardsource
function string.fnv1a(str: string): integer

Returns the Fowler-Noll-Vo (FNV-1a) hash of the string.

Wiki Page

Parameters
NameTypeDescription
strstringThe string used to calculate the Fowler-Noll-Vo hash.
Returns
TypeNameDescription
integerhash_intThe Fowler-Noll-Vo hash, which is greater or equal to 0, and less than 2^32 (0x100000000).

#string.hasPrefix

sharedmenunodiscardsource
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.

Parameters
NameTypeDescription
strstringThe string to check.
prefixstringThe prefix to check for.
offsetoptionalintegerThe number of bytes to skip from the start of str before checking. Defaults to 0.
Returns
TypeNameDescription
booleanhas_prefixtrue if the string starts with the prefix (at the given offset), false otherwise.

#string.hasSuffix

sharedmenunodiscardsource
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.

Parameters
NameTypeDescription
strstringThe string to check.
suffixstringThe suffix to check for.
offsetoptionalintegerThe number of bytes to ignore at the end of str before checking. Defaults to 0.
Returns
TypeNameDescription
booleanhas_suffixtrue if the string ends with the suffix (at the given offset), false otherwise.

#string.indent

sharedmenunodiscardsource
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.

Parameters
NameTypeDescription
strstringThe string to indent.
sizeintegerThe number of spaces the result should start with.
Returns
TypeNameDescription
stringindentedThe string with its leading whitespace replaced by size spaces.

#string.indentLines

sharedmenunodiscardsource
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.

Parameters
NameTypeDescription
strstringThe string to indent.
sizeintegerThe number of spaces each line should start with.
Returns
TypeNameDescription
stringindentedThe string with every line re-indented to size spaces.

#string.indexOf

sharedmenunodiscardsource
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".

Parameters
NameTypeDescription
strstringThe string to search in.
searchablestringThe substring or pattern to search for.
positionoptionalintegerThe position to start searching from, inclusive. Negative values count from the end of the string. Defaults to 1 (the start of the string).
with_patternoptionalbooleanWhen true, searchable is interpreted as a Lua pattern. Defaults to false (plain match).
Returns
TypeNameDescription
integerindexThe index of the first match, 0 if searchable is nil or empty, or -1 if no match is found.

#string.insert

sharedmenunodiscardsource
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.

Parameters
NameTypeDescription
strstringThe string to insert into.
indexintegerThe position to insert at. Defaults to the end of the string; negative values count from the end.
valuestringThe string value to insert.
Returns
TypeNameDescription
stringresultThe string with value inserted at the given position.
Overloads
function string.insert(str: string, value: string): string

#string.interpolate

sharedmenunodiscardsource
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.

Parameters
NameTypeDescription
strstringThe string to interpolate.
variablesstring[] | 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_positionoptionalintegerThe 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_positionoptionalintegerThe 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.
Returns
TypeNameDescription
stringstrThe interpolated string.
See also
  • string.format

#string.interpolateByte

sharedmenunodiscardsource
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.

Parameters
NameTypeDescription
strstringThe string to interpolate.
interpolate_byteintegerThe byte value that acts as a placeholder marker.
variablesstring[]The replacement values, used in order of occurrence within the string.
variable_countoptionalintegerThe 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_positionoptionalintegerThe 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_positionoptionalintegerThe 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.
Returns
TypeNameDescription
stringstrThe interpolated string.

#string.isBytecode

sharedmenunodiscardsource
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.

Parameters
NameTypeDescription
strstringThe string to check.
jit_version`0x01` | `0x02` | integerThe expected LuaJIT bytecode version byte to match against (see jit.version_byte).
start_positionoptionalintegerThe position in str where the bytecode header is expected to start. Defaults to 1 (the start of the string).
Returns
TypeNameDescription
booleanresulttrue if str starts with a matching LuaJIT bytecode header at start_position, false otherwise.

#string.isEmpty

sharedmenunodiscardsource
function string.isEmpty(str: string): boolean

Checks whether a string is empty, i.e. has no bytes at all.

Parameters
NameTypeDescription
strstringThe string to check.
Returns
TypeNameDescription
booleanresulttrue if str has zero length, false otherwise.

#string.isNumber

sharedmenunodiscardsource
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.

Parameters
NameTypeDescription
strstringThe string to check.
baseoptionalintegerThe 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_positionoptionalintegerThe position to start checking from. Defaults to 1 (the start of the string).
end_positionoptionalintegerThe position to stop checking at. Defaults to the end of the string.
Returns
TypeNameDescription
booleanis_numbertrue if the (sub)string is a valid number in the given base, false otherwise.

#string.isURL

sharedmenunodiscardsource
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.

Parameters
NameTypeDescription
strstringThe string to check.
Returns
TypeNameDescription
booleanresulttrue if str matches the expected URL shape, false otherwise.

#string.pack

sharedmenunodiscardsource
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.

Parameters
NameTypeDescription
bytesinteger[]The sequence of bytes to pack, each an integer in the range 0-255.
byte_countoptionalintegerThe number of bytes, from the start of bytes, to pack. Defaults to len( bytes ) (the whole array).
Returns
TypeNameDescription
stringstrThe packed byte string.

#string.pad

sharedmenunodiscardsource
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.

Parameters
NameTypeDescription
strstringThe string to pad.
desired_lengthintegerThe target length, in bytes, that the result should reach.
paddingoptionalstringThe string to pad with, repeated as needed. Defaults to a single space.
leftoptionalbooleanWhether to add padding on the left side.
rightoptionalbooleanWhether to add padding on the right side.
Returns
TypeNameDescription
stringpadded_strThe padded string, or str unchanged if no padding was needed or requested.

#string.purge

sharedmenunodiscardsource
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.

Parameters
NameTypeDescription
strstringThe string to purge.
byteintegerThe byte value to remove.
start_positionoptionalintegerThe position to start purging from, inclusive. Bytes outside this range are left untouched.
end_positionoptionalintegerThe position to stop purging at, inclusive. Bytes outside this range are left untouched.
Returns
TypeNameDescription
stringstr_purgedThe string with every occurrence of byte removed.

#string.quote

sharedmenunodiscardsource
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.

Parameters
NameTypeDescription
strstringThe string to quote.
use_singleoptionalbooleanWhen true, wraps in single quotes (') and escapes any ' inside str. When false/omitted, wraps in double quotes (") and escapes any " inside str.
Returns
TypeNameDescription
stringresultThe quoted string.

#string.random

sharedmenunodiscardsource
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.

Parameters
NameTypeDescription
lengthoptionalintegerThe length of the string, defaults to 8.
lowercaseoptionalbooleanWhether to include lowercase letters (a-z). Defaults to true.
uppercaseoptionalbooleanWhether to include uppercase letters (A-Z). Defaults to false.
numbersoptionalbooleanWhether to include digits (0-9). Defaults to true.
symbolsoptionalbooleanWhether to include symbol/punctuation characters. Defaults to false.
extended_asciioptionalbooleanWhether to include extended (non-ASCII, above 0x7F) characters. Defaults to false.
Returns
TypeNameDescription
stringresultA randomly generated string of the requested length, drawn from the enabled character pools.

#string.remove

sharedmenunodiscardsource
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.

Parameters
NameTypeDescription
strstringThe string to remove from.
start_positionintegerThe 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_positionintegerThe end position of the removal interval, inclusive. Negative values count from the end of the string. Defaults to the end of the string.
Returns
TypeNameDescription
stringnew_stringThe string with the specified byte interval removed.

#string.replace

sharedmenunodiscardsource
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.

Parameters
NameTypeDescription
strstringThe string we are seeking to replace an occurrence(s) in.
searchableoptionalstringWhat we are seeking to replace, or the substring or pattern to split by.
replaceableoptionalstringWhat to replace it with. If nil, occurrences are removed.
with_patternoptionalbooleanWhen true, searchable is interpreted as a Lua pattern. Defaults to false (plain match).
start_positionoptionalintegerThe position to start replacing from, inclusive. Matches outside this range are left untouched.
end_positionoptionalintegerThe position to stop replacing at, inclusive. Matches outside this range are left untouched.
Returns
TypeNameDescription
stringstr_replacedThe new string with the occurrences replaced.

#string.split

sharedmenunodiscardsource
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.

Parameters
NameTypeDescription
strstringThe string to split.
searchableoptionalstringThe substring or pattern to split by. If nil or empty, splits into individual bytes instead.
with_patternoptionalbooleanWhen true, searchable is interpreted as a Lua pattern. Defaults to false (plain match).
start_positionoptionalintegerThe 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_positionoptionalintegerThe 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.
Returns
TypeNameDescription
string[]segmentsThe resulting array of substrings.
integersegment_countThe number of entries in segments.

#string.toNumber

sharedmenunodiscardsource
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.

Parameters
NameTypeDescription
strstringThe string to convert.
baseoptionalintegerThe 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_positionoptionalintegerThe position to start converting from. Defaults to 1 (the start of the string).
end_positionoptionalintegerThe position to stop converting at. Defaults to the end of the string.
Returns
TypeNameDescription
number | nilnumThe converted number, or nil if the (sub)string is not a valid number in the given base.

#string.trim

sharedmenunodiscardsource
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.

Parameters
NameTypeDescription
strstringThe string to trim.
pattern_stroptionalstringThe 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).
leftoptionalbooleanWhether to trim from the start of the string. Defaults to true.
rightoptionalbooleanWhether to trim from the end of the string. Defaults to true.
Returns
TypeNameDescription
stringtrimmed_strThe trimmed string.

#string.trimByte

sharedmenunodiscardsource
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.

Parameters
NameTypeDescription
strstringThe string to trim.
trailing_byteoptionalintegerThe byte value to trim from the start and/or end. Defaults to 0x20 (space).
leftoptionalbooleanWhether to trim from the start of the string. Defaults to true.
rightoptionalbooleanWhether to trim from the end of the string. Defaults to true.
start_positionoptionalintegerThe position to start trimming within, inclusive. Negative values count from the end of the string. Defaults to 1 (the start of the string).
end_positionoptionalintegerThe position to stop trimming within, inclusive. Negative values count from the end of the string. Defaults to the end of the string.
Returns
TypeNameDescription
stringtrimmed_strThe trimmed string.
integertrimmed_lengthThe length of the trimmed string.

#string.trimSpaces

sharedmenunodiscardsource
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.

Parameters
NameTypeDescription
strstringThe string to trim.
leftoptionalbooleanWhether to trim from the start of the string. Defaults to true.
rightoptionalbooleanWhether to trim from the end of the string. Defaults to true.
start_positionoptionalintegerThe position to start trimming within, inclusive. Negative values count from the end of the string. Defaults to 1 (the start of the string).
end_positionoptionalintegerThe position to stop trimming within, inclusive. Negative values count from the end of the string. Defaults to the end of the string.
Returns
TypeNameDescription
stringtrimmed_strThe trimmed string.
integertrimmed_lengthThe length of the trimmed string.

#string.unescape

sharedmenunodiscardsource
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.

Parameters
NameTypeDescription
escaped_strstringThe string to unescape.
start_positionoptionalintegerThe position to start unescaping from, inclusive. Negative values count from the end of the string. Defaults to 1 (the start of the string).
end_positionoptionalintegerThe position to stop unescaping at, inclusive. Negative values count from the end of the string. Defaults to the end of the string.
Returns
TypeNameDescription
stringstrThe unescaped string.
See also

#string.unIndent

sharedmenunodiscardsource
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 ).

Parameters
NameTypeDescription
strstringThe string to unindent.
sizeoptionalintegerThe maximum number of leading whitespace bytes to remove. Defaults to removing all of them.
Returns
TypeNameDescription
stringunindentedThe string with leading whitespace removed.

#string.unindentLines

sharedmenunodiscardsource
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.

Parameters
NameTypeDescription
strstringThe string to unindent.
sizeoptionalintegerThe maximum number of leading whitespace bytes to remove from each line. Defaults to removing all of them.
Returns
TypeNameDescription
stringunindentedThe string with leading whitespace removed from every line.

#string.unpack

sharedmenunodiscardsource
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.

Parameters
NameTypeDescription
strstringThe string to unpack.
start_positionoptionalintegerThe position to start unpacking from, inclusive. Negative values count from the end of the string. Defaults to 1 (the start of the string).
end_positionoptionalintegerThe 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 )).
Returns
TypeNameDescription
integer[]bytesThe unpacked bytes, one entry per byte in the range.
integerbyte_countThe number of bytes unpacked (i.e. #bytes).

#string.unQuote

sharedmenunodiscardsource
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.

Parameters
NameTypeDescription
strstringThe string to unquote.
use_singleoptionalbooleanWhen true, expects and strips single quotes (') and unescapes \' inside str. When false/omitted, expects and strips double quotes (") and unescapes \" inside str.
Returns
TypeNameDescription
stringresultThe unquoted string, or str unchanged (with unescaping still applied) if it wasn't wrapped in the expected quote character.
Generated from the dreamwork meta branch.