运算符 | 描述 | 例子 |
---|---|---|
.. | 连接两个字符串 | a..b,如果a是“hello”,b是“world”,则连接起来是“helloworld” |
# | 一元运算符返回一个字符串或者一个表的长度 | #“hello” 返回的是5 |
简单例程:
1运算符: ..
tab1 = { key1 = "val1", key2 = "val2", "val3" }
for k, v in pairs(tab1) do
print(k .. " - " .. v)
end
输出结果:
1 - val3
key1 - val1
key2 - val2
>Exit code: 0
2 运算符:#
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