1.向table里面动态添加值:

local t={}
for i=1,10 do
table.insert(t,i)
end

for k,v in pairs(t) do
print(k,v)
end

Lua的系统库

2.向table中删除值:

local t={}
for i=1,10 do
table.insert(t,i)
end

table.remove(t,2)

for k,v in pairs(t) do
print(k,v)
end

Lua的系统库

3.删除映射

local t={}
t.a=1
t.b=2

t.a=nil

for k,v in pairs(t) do
print(k,v)
end

Lua的系统库

4.求table和字符串中元素个数:

local t={5,1,3,4}
print(#t)
local m="Hello World"
print(#m)

Lua的系统库

5.查看自变量的类型

local t="hello world"
print(type(t))

Lua的系统库

5.数值与字符串的转化

local a=tonumber("3.14")
print(a,type(a))
local m=tostring(3.14)
print(m,type(m))

Lua的系统库

6.输出格式化

print(string.format("hi %d",2))

Lua的系统库

相关文章:

  • 2022-12-23
  • 2021-05-29
  • 2022-12-23
  • 2021-07-14
  • 2021-11-21
  • 2021-05-19
  • 2021-10-20
  • 2022-12-23
猜你喜欢
  • 2021-10-27
  • 2021-08-08
  • 2021-05-15
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案