Lua杂项运算符示例

Lua语言支持的其他运算符包括连接和长度。

编号 描述 示例
.. 连接两个字符串 如果aHellobWorlda..b将返回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

上一篇: Lua运算符 下一篇: Lua循环