Reading — step 1 of 5
Learn
~1 min readStrings
Strings are immutable. Single or double quotes work; both behave identically. Multiline strings use [[ ... ]].
Concatenation uses .. (NOT +):
local first = "Grace"
local last = "Hopper"
print(first .. " " .. last) -- Grace Hopper
Length uses the # operator:
print(#"hello") -- 5
String library essentials:
string.upper("hi") -- HI
string.lower("HI") -- hi
string.sub("hello", 2, 4) -- ell (1-indexed, inclusive)
string.rep("ab", 3) -- ababab
string.find("hello", "ll") -- 3, 4
Method-style works too: ("hi"):upper().
Discussion
Ask a question, share an insight, or help someone who’s stuck.
Sign in to post a comment or reply.
Loading…