如何打印表元素的首个字符?

假设你有以下表格:

mytable = {"firstelement", "secondelement", "thirdelement" }

print (mytable [1])
==> firstelement

如何使它只打印出“firstelement”中的“f”??

原文链接 https://stackoverflow.com/questions/7305718

点赞
stackoverflow用户513763
stackoverflow用户513763

这是一个简单的字符串操作:

print(mytable[1]:sub(1,1))

更多信息可以在Lua用户字符串库教程Lua参考手册中的字符串操作中找到。

2011-09-05 09:18:43
stackoverflow用户169828
stackoverflow用户169828
`print( mytable[1]:sub(1, 1) )`

mytable 表的第一个元素的第一个字符打印出来。

2011-09-05 09:20:05