#在lua中的运用

时间:2023-11-29 14:01:32

在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
Length of b is

例子二,对多维表的计算:

th> tags={{1,2,3},{3,4,4}}
th> #tags
2

例子三,

th> tags={,,}
[.0001s]
th> tags[#tags+]=
[.0001s]
th> tags
{
:
:
:
:
}