Skip to content

Instantly share code, notes, and snippets.

@OutlawGameTools
Created January 4, 2016 12:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OutlawGameTools/b982c2c4ad1ebee11a55 to your computer and use it in GitHub Desktop.
Save OutlawGameTools/b982c2c4ad1ebee11a55 to your computer and use it in GitHub Desktop.
Corona SDK. Use like split -- pass in divider character and a string and get back a table/array holding each piece between the dividers.
-- works like PHP explode() function
function explode(div,str) -- credit: http://richard.warburton.it
if (div=='') then return false end
local pos,arr = 0,{}
-- for each divider found
for st,sp in function() return string.find(str,div,pos,true) end do
table.insert(arr,string.sub(str,pos,st-1)) -- Attach chars left of current divider
pos = sp + 1 -- Jump past current divider
end
table.insert(arr,string.sub(str,pos)) -- Attach chars right of last divider
return arr
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment