this is hard to explain for me, i need a to create a 2d table according to how a string is inputted, the tables are created for each delimiter it finds in the string, first delimiter i use is "," - which creates a tables inside the current table index for each alphanumeric character it finds in the message, the second delimiter i use is "|" - it creates a new table, and every word before "," it finds after "|" will be put into the new table
heres what i have:
local function SortMessageToTable(Message, Delimiter) local out = {} for word in (Message .. Delimiter):gmatch("(%w-)" .. Delimiter) do table.insert(out, word) end return out end local SortedMessage = SortMessageToTable(Message, "|") for i = 1, #SortedMessage do SortedMessage[i] = SortMessageToTable(SortedMessage[i], ",") end
what i'm trying to get: input = "test1, test2 | test2, test1"
result = table1: {"test2", "test2"} table2: {"test1", "test1"}
what i want to be getting is = table1: {"test1", "test2"} table2: {"test2", "test1"}
for some reason it just gets the last word it finds before "|" and sets every field in the table index to it. does anyone know how to fix this? it would be very appreciated
The output of your script is not what you're saying... so I'm not sure what you're doing.
"%w-" .. Delimiter
requires every word ("%w-"
) to be immediately followed by the delimiter.
Use what I suggested before: "(.-)" .. Delimiter
or "[^" .. Delimiter .. "]*" .. Delimiter
or something similar.
Locked by User#24403
This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.
Why was this question closed?