Lua 自定義函數string.split

function string.split(str, delimiter)
    if str==nil or str=='' or delimiter==nil then
        return nil
    end
    
    local result = {}
    for match in (str..delimiter):gmatch("(.-)"..delimiter) do
        table.insert(result, match)
    end
    return result
end
--測試
local str = "1234,389,abc";
local list = string.split(str, ",");

測試

相關文章
相關標籤/搜索