Programming in Lua - 2.4
Programming in Lua - 2.4
Programming in Lua
Part I. The Language
Chapter 2. Types and Values
2.4 – Strings
Strings have the usual meaning:
a sequence of characters.
Lua is eight-bit
clean
and so strings may contain characters with any numeric value,
including embedded zeros.
That means that you can store any binary data
into a string.
Strings in Lua are immutable values.
You cannot change a
character inside a string,
as you may in C;
instead, you create a new string
with the desired modifications,
as in the next example:
a = "one string"
a = "a line"
b = 'another line'
As a matter of style,
you should use always the same kind of quotes
(single or
double) in a program,
unless the string itself has quotes;
then you use the
other quote,
or escape those quotes with backslashes.
Strings in Lua can
contain the following C-like escape sequences:
\a bell
\b back space
\f form feed
\n newline
\r carriage return
\t horizontal tab
\v vertical tab
\\ backslash
\" double quote
\' single quote
\[ left square bracket
\] right square bracket
one line
next line
page = [[
<HTML>
<HEAD>
</HEAD>
<BODY>
<A HREF="http://www.lua.org">Lua</A>
</BODY>
</HTML>
]]
write(page)
if n == nil then
else
print(n*2)
end