1

# How do I use string concatenation in Lua?

Could someone tell me how i should use it and what its good for?

3
Merely 2117
7 years ago

Concatenation is when you join together two strings. In lua, the concatenation operator is ..

Here's a quick example:

local message = "Merely" .. " has eaten a snowball."


2

String concatenation is used to combine two strings. The string concatenation "character" in Lua is .. (two periods).

print("Hi" .. " World!")

x = "yo"
y = "dog"
print(x .. " " .. y)

-- etc


1
Unclear 1776
7 years ago

Concatenation is the combination of two Strings into one. This can be useful when you're working with any type of Strings. A good example is referencing a set of objects following a rule (obj1, obj2, obj3...).

The concatenation symbol in Lua is .. (two periods), and combines the left string with the right string.

Here's an example...

print("h" .. "i")

1

Say if you have a player entered script. You do it like this...

game.Players.PlayerAdded:connect(function(plr)
msg = Instance.new("Message", Workspace)
msg.Text = "Say welcome to "...plr.Name
wait(2)
msg:Destroy()
end)


It basically allows strings and values to be added into something.

0
Minifig77 190
7 years ago

Concatenation is when you combine two strings. Basically, you put two dots in between two strings or other values that can be used in a string. Example:

Player = "Minifig77"
WinPercentage = 100

print("Player "..Player.." wins "..WinPercentage.."% of the time!"


In the output, you would see: Player Minifig77 wins 100% of the time!

0
Edited 3 years ago
game.Players.PlayerAdded:connect(function(plr)
msg = Instance.new("Name", Workspace)
msg.Text = "Welcome to "Game, plr.Name!
wait(2)
msg:Destroy()
end)