Table of Contents

Lua字符串


分割

-- 解析字符串:10000=1|10001=5
-- 结果像这样:{{10001,1}, {10003,2}, {10000,5}}
function UI_Sys_AwardChoice:_analyGiftContent(kStr)
    local kResult = {}
 
    for kSingleStr in string.gmatch(kStr, "([^|]+)") do
        local kCahce = {}
        for kNumber in string.gmatch(kSingleStr, "([^=]+)") do
            table.insert(kCahce, math.floor(tonumber(kNumber))) -- 字符串变整数
        end
        if #kCahce == 2 then
            table.insert(kResult, {kCahce[1], kCahce[2]})
        else print('Cant Analy _kSelectReward: '..kStr) end
    end
 
    return kResult
end

子串

string.sub(kStr, l, r)