Zhonghui

每个不曾起舞的日子,都是对生命的辜负

User Tools

Site Tools


程序:lua:字符串

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)
/var/www/DokuWikiStick/dokuwiki/data/pages/程序/lua/字符串.txt · Last modified: 2022/09/19 03:29 by zh