- Lua Quick Start Guide
- Gabor Szauer
- 133字
- 2021-08-05 10:30:38
Concatenate strings
Two strings can be concatenated by placing a .. symbol between them. It is very important to have at least one space on both the left and right of the .. symbol. Concatenating two strings results in a new string, which can be stored in a variable or used in its place. Any combination of variables and literals can be concatenated, as the following code demonstrates:
name = "Mike"
color = "Blue"
-- Concatenate three strings
print ("Jill " .. "likes" .. " Red")
-- Concatenate a variable and a strings
print ("Jack dislikes " .. color)
-- Concatenate two variables and a string
print (name .. " likes " .. color)
-- Concatenate only variables
print (name .. color)
-- Assign result to variable
message = name .. " likes " .. color
print (message)