Skip to content

Instantly share code, notes, and snippets.

@rickysaltzer
Created January 8, 2014 16:36
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 rickysaltzer/8319754 to your computer and use it in GitHub Desktop.
Save rickysaltzer/8319754 to your computer and use it in GitHub Desktop.
Found on the internet, saving for later
-- Generic split function found on the internet
-- http://coronalabs.com/blog/2013/04/16/lua-string-magic/
function string:split( inSplitPattern, outResults )
if not outResults then
outResults = { }
end
local theStart = 1
local theSplitStart, theSplitEnd = string.find( self, inSplitPattern, theStart )
while theSplitStart do
table.insert( outResults, string.sub( self, theStart, theSplitStart-1 ) )
theStart = theSplitEnd + 1
theSplitStart, theSplitEnd = string.find( self, inSplitPattern, theStart )
end
table.insert( outResults, string.sub( self, theStart ) )
return outResults
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment