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.

Cheat sheet

The string concatenation operator .. joins two or more strings together:

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

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

Concatenation doesn't automatically add spaces - include them explicitly with " ".

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