Lua - Miscellaneous operators



Miscellaneous operators supported by Lua Language include concatenation and length.

Operator Description Example
.. Concatenates two strings. a..b where a is "Hello " and b is "World", will return "Hello World".
# An unary operator that return the length of the a string or a table. #"Hello" will return 5

Example - Concatenate Operation

In this example, we're creating two variables a, b and using concatenate operators, we've performed concatenation operation on two strings and printed the results −

main.lua

a = "Hello "
b = "World"

print("Concatenation of string a with b is ", a..b )

Output

When you build and execute the above program, it produces the following result −

Concatenation of string a with b is    Hello World

Example - Length Operation

In this example, we're creating two variables a, b and using length operator, we've printed length of each strings and printed the results −

main.lua

b = "World"

print("Length of b is ",#b )

print("Length of Test is ",#"Test" )

Output

When you build and execute the above program, it produces the following result −

Length of b is 	5
Length of b is 	4
lua_operators.htm
Advertisements