试试这个例子
function split(pString, pPattern)
if string.find(pString,".") then
pString = string.gsub(pString,"%.","'.'")
end
if pPattern == "." then
pPattern = "'.'"
end
local Table = {} -- NOTE: use {n = 0} in Lua-5.0
local fpat = "(.-)" .. pPattern
local last_end = 1
local s, e, cap = pString:find(fpat, 1)
while s do
if s ~= 1 or cap ~= "" then
table.insert(Table,cap)
end
last_end = e+1
s, e, cap = pString:find(fpat, last_end)
end
if last_end <= #pString then
cap = pString:sub(last_end)
table.insert(Table, cap)
end
return Table
end
local myDataTable = split("345345.57573",".")
--Loop Through and print the last split data table
print(myDataTable[1]) --345345
print(myDataTable[2]) --57573
参考