Skip to content

stringlib

byte

function string.byte(s: string|number, i?: integer, j?: integer)
  -> ...integer

Returns the internal numeric codes of the characters s[i], s[i+1], ..., s[j].

View documents

char

function string.char(byte: integer, ...integer)
  -> string

Returns a string with length equal to the number of arguments, in which each character has the internal numeric code equal to its corresponding argument.

View documents

dump

function string.dump(f: fun(...any):...unknown, strip?: boolean)
  -> string

Returns a string containing a binary representation (a binary chunk) of the given function.

View documents

find

function string.find(s: string|number, pattern: string|number, init?: integer, plain?: boolean)
  -> start: integer|nil
  2. end: integer|nil
  3. ...any

Looks for the first match of pattern (see §6.4.1) in the string.

View documents

@return start

@return end

@return ... — captured

format

function string.format(s: string|number, ...any)
  -> string

Returns a formatted version of its variable number of arguments following the description given in its first argument.

View documents

gmatch

function string.gmatch(s: string|number, pattern: string|number, init?: integer)
  -> fun():string, ...unknown

Returns an iterator function that, each time it is called, returns the next captures from pattern (see §6.4.1) over the string s.

As an example, the following loop will iterate over all the words from string s, printing one per line:

    s =
"hello world from Lua"
    for w in string.gmatch(s, "%a+") do
        print(w)
    end

View documents

gsub

function string.gsub(s: string|number, pattern: string|number, repl: string|number|function|table, n?: integer)
  -> string
  2. count: integer

Returns a copy of s in which all (or the first n, if given) occurrences of the pattern (see §6.4.1) have been replaced by a replacement string specified by repl.

View documents

len

function string.len(s: string|number)
  -> integer

Returns its length.

View documents

lower

function string.lower(s: string|number)
  -> string

Returns a copy of this string with all uppercase letters changed to lowercase.

View documents

match

function string.match(s: string|number, pattern: string|number, init?: integer)
  -> ...any

Looks for the first match of pattern (see §6.4.1) in the string.

View documents

pack

function string.pack(fmt: string, v1: string|number, v2?: string|number, ...string|number)
  -> binary: string

Returns a binary string containing the values v1, v2, etc. packed (that is, serialized in binary form) according to the format string fmt (see §6.4.2) .

View documents

packsize

function string.packsize(fmt: string)
  -> integer

Returns the size of a string resulting from string.pack with the given format string fmt (see §6.4.2) .

View documents

rep

function string.rep(s: string|number, n: integer, sep?: string|number)
  -> string

Returns a string that is the concatenation of n copies of the string s separated by the string sep.

View documents

reverse

function string.reverse(s: string|number)
  -> string

Returns a string that is the string s reversed.

View documents

sub

function string.sub(s: string|number, i: integer, j?: integer)
  -> string

Returns the substring of the string that starts at i and continues until j.

View documents

unpack

function string.unpack(fmt: string, s: string, pos?: integer)
  -> ...any
  2. offset: integer

Returns the values packed in string according to the format string fmt (see §6.4.2) .

View documents

upper

function string.upper(s: string|number)
  -> string

Returns a copy of this string with all lowercase letters changed to uppercase.

View documents