6.4 – String Manipulation

This library provides generic functions for string manipulation, such as finding and extracting substrings, and pattern matching. When indexing a string in Lua, the first character is at position 1 (not at 0, as in C). Indices are allowed to be negative and are interpreted as indexing backwards, from the end of the string. Thus, the last character is at position -1, and so on.

The string library provides all its functions inside the table string. It also sets a metatable for strings where the __index field points to the string table. Therefore, you can use the string functions in object-oriented style. For instance, string.byte(s,i) can be written as s:byte(i).

The string library assumes one-byte character encodings.

string.find()
  • References/Lua/Lua/Standard Libraries/String Manipulation

string.find (s, pattern [, init [, plain]]) Looks for the first match of pattern (see

2025-01-10 15:47:30
string.format()
  • References/Lua/Lua/Standard Libraries/String Manipulation

string.format (formatstring, ···) Returns a formatted version of its variable number of arguments following the description given in its first argument (which must be a string)

2025-01-10 15:47:30
string.pack()
  • References/Lua/Lua/Standard Libraries/String Manipulation

string.pack (fmt, v1, v2, ···) Returns a binary string containing the values v1, v2, etc. packed (that is, serialized in binary form) according to the

2025-01-10 15:47:30
string.lower()
  • References/Lua/Lua/Standard Libraries/String Manipulation

string.lower (s)

2025-01-10 15:47:30
string.char()
  • References/Lua/Lua/Standard Libraries/String Manipulation

string.char (···) Numeric codes are not necessarily portable across platforms.

2025-01-10 15:47:30
string.reverse()
  • References/Lua/Lua/Standard Libraries/String Manipulation

string.reverse (s)s

2025-01-10 15:47:30
string.len()
  • References/Lua/Lua/Standard Libraries/String Manipulation

string.len (s)"""a\000bc\000"

2025-01-10 15:47:30
string.packsize()
  • References/Lua/Lua/Standard Libraries/String Manipulation

string.packsize (fmt) Returns the size of a string resulting from string

2025-01-10 15:47:30
string.unpack()
  • References/Lua/Lua/Standard Libraries/String Manipulation

string.unpack (fmt, s [, pos]) Returns the values packed in string s (see

2025-01-10 15:47:30