Posted 01 March 2013 - 10:00 AM
Hey guys, I brought this up inside another one of my threads but here it is again.
When I leave the <pat> empty ("") it returns an empty table, I'm hoping for it to split each letter up and not nothing…
When I leave the <pat> empty ("") it returns an empty table, I'm hoping for it to split each letter up and not nothing…
function split(str,pat)
local t = {}
local fpat = "(.-)" .. pat
local last_end = 1
local s, e, cap = str:find(fpat, 1)
while s do
if s ~= 1 or cap ~= "" then
table.insert(t,cap)
end
last_end = e+1
s, e, cap = str:find(fpat, last_end)
end
if last_end <= #str then
cap = str:sub(last_end)
table.insert(t, cap)
end
return t
end