lua split实现(lua程序设计10.6练习10.1题)
local function split(s,sp)local t = {}local last = 1local irepeati = string.find(s,sp,last,true)if i thenif i ~= last thent[#t+1] = string.sub(s,last,i-1)endlast = i+1elseif last <= #s thent[#t+1] = string.sub(s,last,#s)enduntil not ireturn table.concat(t,sp)
endlocal t = split("a whole new world"," ")
print(t)