EasyManuals Logo

Embedded Systems LM5p-GSMC User Manual

Default Icon
291 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #104 background imageLoading...
Page #104 background image
104
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). 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
string.format('%q', 'a string with "quotes" and \n new line')
will produce the string:
"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, except
as arguments to the q option.
string.gmatch (s, pattern)
Returns an iterator function that, each time it is called, returns the next captures from pattern
over strings. If pattern specifies no captures, then the whole match is produced in each call. As
an example, the following loop
1.
s ="hello world from Lua"
2.
for w instring.gmatch(s, "%a+")do
3.
print(w)
4.
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:
1.
t ={}
2.
s ="from=world, to=Lua"
3.
for k, v instring.gmatch(s, "(%w+)=(%w+)") do
4.
t[k]= v
5.
end
For this function, a '^' at the start of a pattern does not work as an anchor, as this would
prevent the iteration.
string.gsub (s, pattern, repl [, n])
Returns a copy of s in which all (or the first n, if given) occurrences of the pattern have been
replaced by are placement string specified by repl, which can be a string, a table, or a function.
gsub also returns, as its second value, the total number of matches that occurred.
If repl is a string, then its value is used for replacement. The character % works as an escape
character:any sequence in repl of the form %n, with n between 1 and 9, stands for the value of
the n-th capture dsub string (see below). The sequence %0 stands for the whole match. The
sequence %% stands for a single %.
If repl is a table, then the table is queried for every match, using the first capture as the key; if
the pattern specifies no captures, then the whole match is used as the key.

Table of Contents

Other manuals for Embedded Systems LM5p-GSMC

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Embedded Systems LM5p-GSMC and is the answer not in the manual?

Embedded Systems LM5p-GSMC Specifications

General IconGeneral
BrandEmbedded Systems
ModelLM5p-GSMC
CategoryDimmer
LanguageEnglish

Related product manuals