sorting a string to tables algorithm? [closed]
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:
01 | local function SortMessageToTable(Message, Delimiter) |
03 | for word in (Message .. Delimiter):gmatch( "(%w-)" .. Delimiter) do |
04 | table.insert(out, word) |
10 | local SortedMessage = SortMessageToTable(Message, "|" ) |
11 | for i = 1 , #SortedMessage do |
12 | SortedMessage [ i ] = SortMessageToTable(SortedMessage [ i ] , "," ) |
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
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?