59
1.2.18.
String functions
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.trim (str)
Trims the leading and trailing spaces off a given string.
string.split (str, sep)
Splits string by given separator string. Returns Lua table.
string.byte (s [, i [, j]])
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 (···)
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 corresponding argument.
Note that numerical codes are not necessarily portable across platforms.
string.find (s, pattern [, init [, plain]])
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 can 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, ···)
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:
Summary of Contents for LogicMachine3 Re:actor
Page 10: ...10 Terminal connection schemes KNX TP...
Page 12: ...12 24V power supply...
Page 13: ...13 Analog inputs e g reed contact...
Page 14: ...14 Analog inputs 0 10V...
Page 15: ...15 Digital output...
Page 16: ...16 Resistive sensor input...
Page 17: ...17 Analog output...
Page 26: ...26 Make sure that bus status is Online press button in ETS...
Page 35: ...35 o Then minimize side bar by pressing on left arrow icon to make the map more visible...
Page 83: ...83 66 if err then 67 alert FTP upload failed s err 68 end...
Page 107: ...107...
Page 108: ...108 1 14 Help Documentation for scripting syntaxes is displayed in Help tab...
Page 126: ...126 Datapoints can be shown also in a way of table which can be later exported as CSV file...
Page 141: ...141...