Skip to content

Instantly share code, notes, and snippets.

@jaredallard
Created May 21, 2015 05:07
Show Gist options
  • Star 21 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save jaredallard/ddb152179831dd23b230 to your computer and use it in GitHub Desktop.
Save jaredallard/ddb152179831dd23b230 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
@Luabee
Copy link

Luabee commented Mar 21, 2017

Thanks mate!

@seblod90
Copy link

Thank you very much! Helped a lot!

@SoldierPePe
Copy link

Thanks..

@lukacat10
Copy link

Thanks!

@GabrielBdeC
Copy link

Check my fork to see some changes that enhaced the code:

https://gist.github.com/GabrielBdeC/b055af60707115cbc954b0751d87ec23

@gameplays12303
Copy link

do you mined if i put this into my utilities module

@Luabee
Copy link

Luabee commented Aug 17, 2023 via email

@gameplays12303
Copy link

are you sure you meant to put the email on the comment

@Luabee
Copy link

Luabee commented Aug 17, 2023

are you sure you meant to put the email on the comment

Thanks, that was awful 😅

@jaredallard
Copy link
Author

To be clear, for anyone else seeing this -- feel free to use it however you see fit. Consider it WTFPL licensed.

@Luabee
Copy link

Luabee commented Aug 17, 2023

Herp, I assumed this was something I wrote 🫥

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment