|
楼主 |
发表于 2009-12-1 14:52:00
|
显示全部楼层
string.split=function(str, pat)
local t = {} -- NOTE: use {n = 0} in Lua-5.0
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
days = "Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday"
tab = string.split(days,",")
for i,v in pairs(tab) do
print(i,v)
end |
|