Concatenation: Difference between revisions

From Legacy Roblox Wiki
Jump to navigationJump to search
>Merlin11188
>PurpleKiwi
Added link to table.concat
Line 48: Line 48:


=== See Also ===
=== See Also ===
 
*[[Function_Dump/Table_Manipulation#table.concat_.28table_.5B.2C_sep_.5B.2C_i_.5B.2C_j.5D.5D.5D.29|table.concat]]
[http://lua-users.org/wiki/StringsTutorial Concatenation]
*[http://lua-users.org/wiki/StringsTutorial Concatenation]

Revision as of 03:10, 20 July 2011

Concatenation

What is Concatenation?

Concatenation is the operation of joining two strings together.

Use Cases

Example
print("Hello" .. " Lua User")

Output:
Hello Lua User

local who = "Lua User"
print("Hello "..who)

Output:
Hello Lua User


Numbers can be concatenated to strings. In this case they are coerced into strings and then concatenated.

Example
print("Green bottles: "..10)

Output:
Green bottles: 10

print(type("Green bottles: "..10))

Output:
string
Strings concatenated onto numbers must have a space after the number (because the interpreter thinks that that's a decimal point!) or else they won't be coerced.
Example
print("There are "..10.." green bottles.")

Output:
malformed number near '10..'

print("There are "..10 .." green bottles.")

Output:
There are 10 green bottles.


See Also