*string.byte()*
Returns the internal numerical codes of the characters `s[i]`,
`s[i+1]`,..., `s[j]`. The default value for {i} is 1; the default
value for {j} is {i}.
Note that numerical codes are not necessarily portable across
platforms.
string.char({...}) *string.char()*
Receives zero or more integers. Returns a string with length equal to
the number of arguments, in which each character has the internal
numerical code equal to its correspondent argument.
Note that numerical codes are not necessarily portable across
platforms.
string.dump({function}) *string.dump()*
Returns a string containing a binary representation of the given
function, so that a later |loadstring()| on this string returns a
copy of the function. {function} must be a Lua function without
upvalues.
string.find({s}, {pattern} [, {init} [, {plain}]]) *string.find()*
Looks for the first match of {pattern} in the string {s}. If it finds
a match, then {find} returns the indices of {s} where this occurrence
starts and ends; otherwise, it returns `nil`. A third, optional
numerical argument {init} specifies where to start the search; its
default value is 1 and may be negative. A value of {true} as a fourth,
optional argument {plain} turns off the pattern matching facilities,
so the function does a plain "find substring" operation, with no
characters in {pattern} being considered "magic". Note that if {plain}
is given, then {init} must be given as well.
If the pattern has captures, then in a successful match the captured
values are also returned, after the two indices.
string.format({formatstring}, {...}) *string.format()*
Returns a formatted version of its variable number of arguments
following the description given in its first argument (which must be a
string). The format string follows the same rules as the `printf`
family of standard C functions. The only differences are that the
options/modifiers `*`, `l`, `L`, `n`, `p`, and `h` are not supported
and that there is an extra option, `q`. The `q` option formats a
string in a form suitable to be safely read back by the Lua
interpreter: the string is written between double quotes, and all
double quotes, newlines, embedded zeros, and backslashes in the string
are correctly escaped when written. For instance, the call
>lua
string.format('%q', 'a string with "quotes" and \n new line')
<
will produce the string:
>lua
"a string with \"quotes\" and \
new line"
<
The options `c`, `d`, `E`, `e`, `f`, `g`, `G`, `i`, `o`, `u`, `X`, and
`x` all expect a number as argument, whereas `q` and `s` expect a
string.
This function does not accept string values containing embedded zeros.
string.gmatch({s}, {pattern}) *string.gmatch()*
Returns an |iterator| function that, each time it is called, returns the
next captures from {pattern} over string {s}.
If {pattern} specifies no captures, then the whole match is produced
in each call.
As an example, the following loop
>lua
s = "hello world from Lua"
for w in string.gmatch(s, "%a+") do
print(w)
end
<
will iterate over all the words from string {s}, printing one per
line. The next example collects all pairs `key=value` from the given
string into a table:
>lua
t = {}
s = "from=world, to=Lua"
for k, v in string.gmatch(s, "(%w+)=(%w+)") do
t[k] = v
end
<
string.gsub({s},