位置:首页 » 文章/教程分享 » Lua其他运算符

通过Lua语言支持其他运算符包括串联和长度。

运算符 描述 例子
.. 连接两个字符串。 a..b 如果a为 "Hello " 并且b为 "World", 那么将返回 "Hello World".
# 一元运算符返回一个字符串或一个表的长度。 #"Hello" 会返回 5

例子

试试下面的例子就明白了在Lua编程语言提供的其他运算符:

a = "Hello "
b = "World"

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

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

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

当建立并执行上面的程序它会产生以下结果:

Concatenation of string a with b is 	Hello World
Length of b is 	5
Length of b is 	4