Concatenation of strings in Lua

Viewed 151295

In many languages you can concatenate strings on variable assignment. I have a scenario, using the Lua programming language, where I need to append the output of a command to an existing variable. Is there a functional equivalent in Lua to the below examples?

Examples of other languages:

===== PERL =====
$filename = "checkbook";
$filename .= ".tmp";
================

===== C# =====
string filename = "checkbook";
filename += ".tmp";
===============
5 Answers

In other languages you would use:

// C#

string a = "Hello";

// 2 Options
a = a + " World!";

// or the easier way:
a += " World!";

Now in Lua: You would use .. , an example here:

-- Lua

local a = "Hello"

-- Sadly Lua doesn't have += so you have to do it this way.
a = a.." World!";
Related