How to print the first character of a table element?
Pergunta
Supose you have the following table:
mytable = {"firstelement", "secondelement", "thirdelement" }
print (mytable [1])
==> firstelement
How do i make it print only the "f" from the "firstelement" ??
Solução
This is a simple string operation:
print(mytable[1]:sub(1,1))
more info can be found in the Lua Users string library tutorial or String manipulation in the Lua Reference manual
Outras dicas
print( mytable[1]:sub(1, 1) )
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow