Created
January 4, 2016 12:00
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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