Skip to content

Instantly share code, notes, and snippets.

@Gnarfoz
Created June 15, 2014 02:51
Show Gist options
  • Save Gnarfoz/97bb9749e7836c42bcff to your computer and use it in GitHub Desktop.
Save Gnarfoz/97bb9749e7836c42bcff to your computer and use it in GitHub Desktop.
local function strsplit(str, delim, maxNb)
-- Eliminate bad cases...
if string.find(str, delim) == nil then
return { str }
end
if maxNb == nil or maxNb < 1 then
maxNb = 0 -- No limit
end
local result = {}
local pat = "(.-)" .. delim .. "()"
local nb = 0
local lastPos
for part, pos in string.gfind(str, pat) do
nb = nb + 1
result[nb] = part
lastPos = pos
if nb == maxNb then break end
end
-- Handle the last field
if nb ~= maxNb then
result[nb + 1] = string.sub(str, lastPos)
end
return result
end
function ByAnotherName:SlashHandler(cmd, msg)
local tokens = strsplit(msg, " ", 2)
for k,v in ipairs(tokens) do
Print(v)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment