5.4 Lua primer
109
%s
String
%q
Quoted string. The string is formatted so that it can safely be read back
by
Lua
.
%%
%. No argument expected.
i,j = string.find(s1, s2, k)
Searches for the substring
s2
in string
s1
and returns the indices for the first and the
last character of
s2
. If
s2
is not a substring of
s1
, the function returns
nil
. The param-
eter
k
is optional and may specify the start index for the search.
t,n = string.gsub(s1,s2,s3,k)
Replaces all occurrences of string
s2
in string
s1
with string
s3
. Returns the resulting
string and the replacement count. The optional parameter
k
can limit the number of
replacements.
The functions
find()
and
gsub()
accept patterns, too—strings with inter-
spersed control sequences. Most control sequences start with “%” followed
by a character, optionally followed by a modifier character (see below).
These control sequences describe character classes such as “letters” or
“digits”.
.
All characters
%a
Letters
%c
Control characters such as new line or form feed
%d
Digits
%l
Lowercase letters
%p
Punctuation characters
%s
Whitespace characters
%u
Uppercase letters
%w
Alphanumeric characters
%x
Hexadecimal digits
%z
The character “0”
%
Escape character. % followed by another character represents the
character itself. Escaping is particularly necessary for the characters
(
)
.
%
+
-
*
?
[
^
$
. For example, “%%” represents “%”.
Using uppercase control characters after the “%” negates the character
class identified by the corresponding lowercase character. For example,
%S
stands for anything except white space.
You can define your own character sets by enclosing the characters be-
longing to the set within brackets:
[+–]
for example, means ‘+’ or ‘–’.
Summary of Contents for Camera
Page 1: ......
Page 2: ...The Canon Camera Hackers Manual ...
Page 3: ......
Page 4: ...Berthold Daum The Canon Camera Hackers Manual Teach Your Camera New Tricks ...
Page 19: ...10 CH APTER 2 Cameras and Operating Systems ...
Page 25: ...16 CH APTER 3 ...
Page 85: ...76 CH APTER 4 Teach Your Camera New Tricks ...
Page 213: ...204 CH APTER 6 ...
Page 253: ...244 AP PENDIX ...