Concatenation: Difference between revisions

From Legacy Roblox Wiki
Jump to navigationJump to search
>Mindraker
New
 
>Nightname
No edit summary
 
(16 intermediate revisions by 6 users not shown)
Line 1: Line 1:
Strings can be joined together using the concatenation operator "..". e.g.,
To quote Wikipedia:
<blockquote cite="https://en.wikipedia.org/w/index.php?title=Concatenation&oldid=483997444">
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".</blockquote>


print("hello" .. " Lua user")<br>
The string concatenation operator in Lua is denoted by two dots (..). Here is an example of concatenation that concatenates "snow" and "ball" :
Will result in:<br>
{{Code and output|
hello Lua user<br>
|code=print("snow" .. "ball")
|output=snowball
}}
That code will concatenate "snow" and "ball" and will print the result, <samp>snowball</samp>.


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


who = "Lua user" <br>
{{code and output
print("hello "..who) <br>
|code=print("Green bottles: " .. 10)
Will result in: <br>
|output=Green bottles: 10
hello Lua user
}}




Numbers can be concatenated to strings. In this case they are [[Coercion|coerced]] into strings and then concatenated.
=== See also ===
print("Green bottles: "..10)<br>
*[[Function_Dump/Table_Manipulation#table.concat_.28table_.5B.2C_sep_.5B.2C_i_.5B.2C_j.5D.5D.5D.29|table.concat]]
Will result in:<br>
*[http://lua-users.org/wiki/StringsTutorial Concatenation]
Green bottles: 10<br>
*[https://en.wikipedia.org/wiki/Concatenation Wikipedia: Concatenation]


and<br>
[[Category:Scripting_Tutorials]]
 
print(type("Green bottles: "..10))<br>
Will result in:<br>
string<br>
 
== See Also ==
 
[http://lua-users.org/wiki/StringsTutorial Concatenation]

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