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
EasyCreate 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)This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
4Operators 2 Relational & Logic
Equality OperatorsRelational OperatorsThe 'and' OperatorThe 'or' OperatorThe 'not' OperatorShort-Circuit EvaluationTruthy and Falsy ValuesRecap - Simple Logic7Basic Conditional Logic
The if-then StatementThe if-then-else StatementThe elseif StatementRecap - Treasure Chest2Variables and Data Types
What is a Variable?NumbersStringsBooleansThe Value 'nil'The type() FunctionNaming ConventionsRecap - Character Profile5Basic Output
Printing LiteralsPrinting VariablesPrinting Multiple ValuesCombining Strings & VariablesThe tostring() FunctionInputCastRecap - Status ReportRecap - Till 1208String Manipulation Basics
string.len()string.upper & string.lowerstring.sub()string.rep()string.find()Recap - Format Username3Operators 1 Arithmetic & Conc
Arithmetic OperatorsModulo OperatorExponentiation OperatorString ConcatenationOperator PrecedenceRecap - Simple Calculations6Project: Character Stats Disp
Welcome MessageDeclare Character Stats9Functions Basics
Declaring a FunctionCalling a FunctionFunctions with ParametersFunctions with Multiple ParamsThe 'return' StatementRecap - Area CalculatorPractice on your own: Online Lua compiler