|
Answer» So I have a table that contains tables that holds a line from a TEXT file, so if the file's first line is "0,0,0,50" then table = { 1 = {a = "0,0,0,50"} 2 = { a = "LINE 2"} 3 = { .....etc. } I want to seperate t[1][a] by commas and STORE each of them in their respective places within the table.
so what I want to do is have it like this: table = { 1 = { a = "0,0,0,50" 1 = 0 2 = 0 3 = 0 4 = 50 } }
What I have so far: function split_comma_String() local b = tablelength(t) print(t[1].a) print(b) repeat local k = 1 local tak = t.a print(tak) for v in string.gmatch(tak, "%w+") do -- error in "%w+" Want to seperate by comma (,) t[k] = v k = k + 1 print(b,b,t[k]) end b = b - 1 until b == 0 end
Nothing that I put in the quotes seems to work. If someone could explain why this is not working that would be very helpful.Oops, I forgot to put it in quotes, so the syntax got all messed up. Code: [Select]function split_comma_String() local b = tablelength(t) print(t[1].a) print(b) repeat local k = 1 local tak = t[b].a print(tak) for v in string.gmatch(tak, "([^,]+)") do -- error in "\,+" Want to separate by comma (,) t[b][k] = v k = k + 1 print(b,b,t[b][k]) end b = b - 1 until b == 0 end
Well I got it to split correctly by using "[^,]+" (though I have no idea why that works). But now it won't set the value into the table.
current code: Code: [Select]function split_comma_String() local b = 1 --print(t[1].a) --print(b) repeat local k = 0 local tak = t[b].a --print(tak) for v in string.gmatch(tak, "[^,]+") do _G["t["..b.."]" ..k] = v -- Not working k = k + 1 print(v ,"t", b, k, t[b][k]) end print("") b = b + 1 until b == t_length end
|