When trying to save a table to a StringValue
I used the tostring()
method and the outcome was a compressed table in a string format.
The result looked like this: table: 0xb506ee799bb044f8
Now I was wondering if I could turn it back into a table exactly how it was before.
This was the code I used if anyone is interested.
script:WaitForChild("Value").Value = tostring({"Hi", "Hello", ["Goodbye"] = {"Bye"}})
I don’t think this is possible. To recieve your desired result, I think something like this would work:
local tableStr = table.concat({ "Test", "test2" }, " ")
Hmm, alright then. How do I reverse the concat then?
You know what after doing some more searching I found something better:
function strToTable(list) -- Comma-Separated-Values to Table
local out = {}
for entry in string.gmatch(list, "[^,]+") do -- [^,] means: anything that is not a comma (the ^ is the not). + means: as many of it in a row as you can get
table.insert(out, entry)
end
return out
end
function tableToStr(list)
return table.concat(list, ",") -- turn the table into one string, with a comma between each value
end
This utilized the concat I told you about before however it removes the { and }
These functions can be used to make a table to a string and reverse
Yea, I tried that but I found it was just too long, I ended up on settling on JSON:Encode()
using
HttpService`.
Yeah I was going to recommend it, however nothing I read said it was working for them, and I’m not on my computer now and didn’t want to give you something that doesn’t work!
Fair enough, thanks though. I am going to do some more research on Stack Overflow but if I find nothing ill just give your method the big green check.
1 Like