Skip to content

Instantly share code, notes, and snippets.

@GabrielBdeC
GabrielBdeC / string.split.lua
Last active February 1, 2021 21:05 — forked from jaredallard/string.split.lua
string.split in lua
--Returns a table splitting some string with a delimiter
--Changes to enhance the code from https://gist.github.com/jaredallard/ddb152179831dd23b230
function string:split(delimiter)
local result = {}
local from = 1
local delim_from, delim_to = string.find(self, delimiter, from, true)
while delim_from do
if (delim_from ~= 1) then
table.insert(result, string.sub(self, from, delim_from-1))
end
@jaredallard
jaredallard / string.split.lua
Created May 21, 2015 05:07
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