Moon, separate string with numbers in a table!

I have a system to redeem codes, in case I would put in a text file something like this:

HFGD65,{2454,2454},1,1

Series:

Code to redeem -- string {items} -- items within the table in numbers points NUM number days numero number

Have I open: for example

local file = 'data/logs/codes.txt'
local f = io.open(file, "rb")
    for k, v in pairs(f) do
 -- retorna aquela linha
end

And I use

local v = ":JH2F36;:{{2173,1},{2160,2}};:0;:1;"
local var = v:gsub(':', ''):explode(';')

To be able to separate, but then I have to use in the txt file like this:

:JH2F36;:{{2173,1},{2160,2}};:0;:1;

Has a different way of calling this line?

Being that the code would have to return string and the more in numbers?

If I separate by", " when I check the table it cuts in the middle and ends there.

Wanted to simplify and find a way to put the code for example:

HB7S5S;{2173,2160}:1:1

How are 4 items there / \ separate by": "

The first would return string (the code) -- HB7S5S

And the other(3) would return:

Number:

(Table)

1

1

Author: Lua Team 91, 2017-03-10

1 answers

You can separate the string with the function string.gmatch()

function separa(s, delimitador)
tab = {};
for valores in (s..delimitador):gmatch("(.-)"..delimiter) do
    table.insert(tab, valores);
end
return result;
end

Or with the function string.match():

function Separa(Cadeia)
     local res = {}
     for pares in string.match(Cadeia, "[^;]+")
     -- aqui também pode ler a linha inteira: "[^\r]*"
     do
        local eq = string.find(pares, "=")
        if eq 
        then
           local chave = pares:sub( 1, eq-1)
           local valor = pares:sub(eq+1,eq+8)

        end
     end
  end   
 1
Author: Rafael Lemos, 2017-07-17 19:46:41