Concatenation: Difference between revisions

From Legacy Roblox Wiki
Jump to navigationJump to search
>Mindraker
New
>Camoy
for examples; formatted; categorized
Line 1: Line 1:
Strings can be joined together using the concatenation operator "..". e.g.,
==Concatenation==
===What is Concatenation?===
Concatenation is the operation of joining two strings together.


print("hello" .. " Lua user")<br>
===Use Cases===
Will result in:<br>
{{Example|<pre>
hello Lua user<br>
print("Hello" .. " Lua User")


and
Output:
Hello Lua User


who = "Lua user" <br>
local who = "Lua User"
print("hello "..who) <br>
print("Hello "..who)
Will result in: <br>
hello Lua user


Output:
Hello Lua User
</pre>}}


Numbers can be concatenated to strings. In this case they are [[Coercion|coerced]] into strings and then concatenated.
Numbers can be concatenated to strings. In this case they are [[Coercion|coerced]] into strings and then concatenated.
print("Green bottles: "..10)<br>
Will result in:<br>
Green bottles: 10<br>


and<br>
{{Example|<pre>
print("Green bottles: "..10)


print(type("Green bottles: "..10))<br>
Output:
Will result in:<br>
Green bottles: 10
string<br>


== See Also ==
print(type("Green bottles: "..10))
 
Output:
string
</pre>}}
 
[[Category:Scripting_Tutorials]]
 
{{EmphasisBox|Strings concatenated onto numbers must have a space after the number of else they won't be coerced.|orange|dark=true}}
 
{{Example|<pre>
print("There are "..10.." green bottles.")
 
Output:
malformed number near '10..'
 
print("There are "..10 .." green bottles.")
 
Output:
There are 10 green bottles.
</pre>}}
 
=== See Also ===


[http://lua-users.org/wiki/StringsTutorial Concatenation]
[http://lua-users.org/wiki/StringsTutorial Concatenation]

Revision as of 13:58, 1 November 2010

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 of 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

Concatenation