I’m trying to convert something like this “{‘Thing1’,‘Thing2’}” to this {‘Thing1’,‘Thing2’}. However, I cannot find any resources on it that function. There is one, but it uses Load(), a function that roblox doesn’t have.
local function eval(s)
return assert(load(s))()
end
local function str2obj(s)
return eval("return " .. s)
end
print(str2obj('{["test"]=""}'))
I made a simple function that converts String to Table:
local function StringToTable(String)
String = string.gsub(String, "{", "")
String = string.gsub(String, "}", "")
local Split = string.split(String, ", ")
local Table = {}
for _, Value in pairs(Split) do
if string.sub(Value, 1, 1) == "[" then
local Index = string.sub(Value, 2, string.find(Value, "]") - 1)
local _Value = string.sub(Value, string.find(Value, "=") + 2, #Value)
Table[Index] = _Value
else
table.insert(Table, Value)
end
end
return Table
end
for i, v in pairs(StringToTable("{['uhh'] = 'idk', [2] = 3}")) do
print(i, v)
end
Make sure to add spaces after a “,” and before and after a "="