Concatenation: Difference between revisions

From Legacy Roblox Wiki
Jump to navigationJump to search
>JulienDethurens
No edit summary
>Nightname
No edit summary
 
(3 intermediate revisions by 2 users not shown)
Line 17: Line 17:
}}
}}


{{EmphasisBox|Strings concatenated into 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.|orange|dark=true}}


=== See also ===
=== See also ===

Latest revision as of 18:32, 28 March 2012

To quote Wikipedia:

In computer programming, string concatenation is the operation of joining two character strings end-to-end. For example, the strings "snow" and "ball" may be concatenated to give "snowball".

The string concatenation operator in Lua is denoted by two dots (..). Here is an example of concatenation that concatenates "snow" and "ball" :

print("snow" .. "ball")
snowball

That code will concatenate "snow" and "ball" and will print the result, snowball.

Numbers can be concatenated to strings, too. In this case they are coerced into strings and then concatenated. For example, suppose you wanted to concatenate "Green bottles: " and 10:

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


See also