#Dv^ Posted September 6, 2017 Posted September 6, 2017 Buenas, quisiera saber si se puede únicamente leer cierto dato de una tabla. Por ejemplo, tengo esta tabla: local _table = { [100] = 1, [150] = 2, [200] = 3 } Entonces, quiero saber si puedo solamente obtener los últimos dos dígitos que están entre corchetes "[ ]". ¿Hay alguna manera?. Agradezco el dato.
alex17" Posted September 6, 2017 Posted September 6, 2017 (edited) local _table = { [100] = 1, [150] = 2, [200] = 3 } for n, k in pairs(_table) do local text = tostring(n) local ftxt = text:gsub(#text - 1)..text:gsub(#text + 1) print ( ftxt ) end prueba esto debe funcionar creo. Edited September 6, 2017 by alex17"
#Dv^ Posted September 6, 2017 Author Posted September 6, 2017 42 minutes ago, alex17" said: local _table = { [100] = 1, [150] = 2, [200] = 3 } for n, k in pairs(_table) do local text = tostring(n) local ftxt = text:gsub(#text - 1)..text:gsub(#text + 1) print ( ftxt ) end prueba esto debe funcionar creo. No me funcionó. ¿Y si quiero por ejemplo obtener solamente los últimos dos dígitos de estos números pero sin estar en una tabla?: 100, 150, 200 PD: Gracias por tu ayuda.
#Dv^ Posted September 6, 2017 Author Posted September 6, 2017 Vuelvo devuelta con el mismo problema, usé string.sub pero no servía la misma propiedad con números más grandes. Quiero saber como obtener los últimos dos dígitos de cualquier número ya sea de 2 o 9 cifras. Agradezco la ayuda.
alex17" Posted September 6, 2017 Posted September 6, 2017 el código que te pase arriba era para cualquier numero de cualquier cifra
#Dv^ Posted September 6, 2017 Author Posted September 6, 2017 (edited) 5 minutes ago, alex17" said: el código que te pase arriba era para cualquier numero de cualquier cifra Me sale "bad argument #2 to 'gsub' (string/function/table expected)" con ese código. Pero ese código que me pasaste, puedo usarlo pero para números que no estén en una tabla o cómo?. Gracias. Edited September 6, 2017 by #Dv^
alex17" Posted September 6, 2017 Posted September 6, 2017 1 minute ago, #Dv^ said: Me sale "bad argument #2 to 'gsub' (string/function/table expected)" con ese código. Pero ese código que me pasaste, puedo usarlo pero para números que no estén en una tabla o cómo?. Gracias. local _table = { [1009] = 1, [1523230] = 2, [2] = 3 } for n, k in pairs(_table) do local text = tostring(n) local ftxt = string.sub (n, #text - 1) outputChatBox(ftxt) end este debe de funcionar
#Dv^ Posted September 6, 2017 Author Posted September 6, 2017 Perfecto, ahora sí. Muchas gracias por tu ayuda!.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now