Skip to content

Instantly share code, notes, and snippets.

@akornatskyy
Last active May 24, 2024 00:36
Show Gist options
  • Select an option

  • Save akornatskyy/63100a3e6a971fd13456b6db104fb65b to your computer and use it in GitHub Desktop.

Select an option

Save akornatskyy/63100a3e6a971fd13456b6db104fb65b to your computer and use it in GitHub Desktop.
Lua: How to separate string with comma
local function split_with_comma(str)
local fields = {}
for field in str:gmatch('([^,]+)') do
fields[#fields+1] = field
end
return fields
end
local function split_with_comma(str)
local r = {}
local i = 1
local p = 1
while true do
local s = str:find(',', p, true)
if not s then
r[i] = str:sub(p)
break
end
r[i] = str:sub(p, s - 1)
p = s + 1
i = i + 1
end
return r
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment