Skip to content

Instantly share code, notes, and snippets.

@JBlaschke
Forked from jaredallard/string.split.lua
Created May 24, 2023 22:28
Show Gist options
  • Save JBlaschke/d79791cd3d153b2940c77dd84e4b6b57 to your computer and use it in GitHub Desktop.
Save JBlaschke/d79791cd3d153b2940c77dd84e4b6b57 to your computer and use it in GitHub Desktop.
string.split in lua
-- split a string
function string:split(delimiter)
local result = { }
local from = 1
local delim_from, delim_to = string.find( self, delimiter, from )
while delim_from do
table.insert( result, string.sub( self, from , delim_from-1 ) )
from = delim_to + 1
delim_from, delim_to = string.find( self, delimiter, from )
end
table.insert( result, string.sub( self, from ) )
return result
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment