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.byte()

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

2017-02-21 04:15:59
string.format()

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)

2017-02-21 04:16:02
string.pack()

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

2017-02-21 04:16:07
string.lower()

string.lower (s)

2017-02-21 04:16:05
string.len()

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

2017-02-21 04:16:05
string.char()

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

2017-02-21 04:16:00
string.unpack()

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

2017-02-21 04:16:10
string.packsize()

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

2017-02-21 04:16:07
string.reverse()

string.reverse (s)s

2017-02-21 04:16:09