local function hasValue(tbl, str) local f = false for ind, val in pairs(tbl) do if type(val) == "table" then hasValue(val, str) else if type(val) == "string" then if string.gsub(val, '^%s*(.-)%s*$', '%1') == string.gsub(str, '^%s*(.-)%s*$', '%1') then f = true end end end end return f end function split(inputstr, sep) sep=sep or '%s' local t={} for field, s in string.gmatch(inputstr, "([^"..sep.."]*)("..sep.."?)") do field = string.gsub(field, '^%s*(.-)%s*$', '%1') table.insert(t, field) if s=="" then return t end end end function tableAsString(tbl) toReturn = "{" for ind, val in pairs(tbl) do if type(val) == "table" then toReturn = toReturn .. (type(ind) == "number" and "" or ind .. "=") .. tableAsString(val) .. "," else local newVal if type(val) == "string" then newVal = "\"" .. val .. "\"" else newVal = val end toReturn = toReturn .. (type(ind) == "number" and "" or ind .. "=") .. newVal .. "," end end toReturn = toReturn:sub(1,-2) .. "}" -- remove trailing "," and close table return toReturn end local b = {} local a = {} local str = 'alpha, bravo, charlie, delta' b = split(str, ',') table.insert(a, b) local str = 'apple, kiwi, banana, pear' b = split(str, ',') table.insert(a, b) local str = 'carrot, brocoli, cabage, potatoe' b = split(str, ',') table.insert(a, b) print(tableAsString(a)) print(hasValue(a, 'brocoli'))