36 lines
560 B
Text
36 lines
560 B
Text
-- Create string.
|
|
local s = "abc"
|
|
|
|
-- Destroy string (not really see notes above).
|
|
s = nil
|
|
|
|
-- (Re)assignment.
|
|
s = "def"
|
|
|
|
-- Comparison.
|
|
local b = (s == "abc") -- false
|
|
local c = (s <= "ghi") -- true
|
|
|
|
-- Cloning/copying.
|
|
local t = s
|
|
|
|
-- Check if empty.
|
|
s = ""
|
|
b = (s != "") -- false
|
|
b = (#s == 0) -- true
|
|
|
|
-- Append a byte.
|
|
s ..= "b"
|
|
|
|
-- Extract a substring.
|
|
s = "ghijkl"
|
|
t = s:sub(2, 5) -- "hijk"
|
|
|
|
-- Replace a byte or string.
|
|
s = "abracadabra"
|
|
s = s:replace("a", "z") -- "zbrzczdzbrz"
|
|
|
|
-- Join strings.
|
|
s = "abc"
|
|
t = "def"
|
|
local u = s .. t -- "abcdef"
|