Menu
Coddy logo textTech

String Concatenation

Part of the Fundamentals section of Coddy's Lua journey. Lesson 15 of 90.

The string concatenation operator represented by two dots .. allows you to join two or more strings together to create a new, longer string.

Here's how string concatenation works:

firstName = "John"
lastName = "Smith"
fullName = firstName .. " " .. lastName    -- fullName is "John Smith"

greeting = "Hello, " .. "World!"          -- greeting is "Hello, World!"

Notice that concatenation doesn't automatically add spaces between strings - you need to include them explicitly. In the example above, we added " " between the first and last name to separate them with a space.

challenge icon

Challenge

Easy

Create a player's full name by combining their first name and last name using string concatenation. Create two variables: firstName with the value "Alex" and lastName with the value "Hunter". Use the concatenation operator to combine these strings with a space between them, storing the result in a variable called fullName. Print the full name.

Try it yourself

-- Create variables for first name and last name
-- TODO: Write your code here

-- Print the full name
print(fullName)
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals

Practice on your own: Online Lua compiler