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.gmatch()
  • References/Lua/Lua/Standard Libraries/String Manipulation

string.gmatch (s, pattern)pattern§6.4.1spattern As

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

string.upper (s)

2025-01-10 15:47:30
Patterns
  • References/Lua/Lua/Standard Libraries/String Manipulation

6.4.1 – Patterns Patterns in Lua are described by regular strings, which are interpreted as patterns by the pattern-matching functions

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

string.dump (function [, strip]) Returns a string containing a binary representation (a binary chunk) of the given function, so that a later

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

string.rep (s, n [, sep])nssepsepn (Note that it is very easy to exhaust the memory of your machine with a single

2025-01-10 15:47:30
Format Strings for Pack and Unpack
  • References/Lua/Lua/Standard Libraries/String Manipulation

6.4.2 – Format Strings for Pack and Unpack The first argument to string.pack

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

string.sub (s, i [, j])sijijjstring.sub(s,1,j)sjstring.sub(s

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

string.byte (s [, i [, j]])s[i]s[i+1]s[j]iji

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

string.gsub (s, pattern, repl [, n])snpattern§6.4.1

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

string.match (s, pattern [, init])matchpattern§6.4.1sma

2025-01-10 15:47:30