cocos2d-lua中function.lua中对于字符串分割函数解释

本文详细解析了Lua中用于字符串分割的function.lua函数,通过具体代码示例展示了如何使用此函数进行字符串处理,并预告了下一期将介绍Lua中的for循环语法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

function split(input, delimiter)
    input = tostring(input)
    delimiter = tostring(delimiter)
    if (delimiter=='') then return false end
    local pos,arr = 0, {}
    -- for each divider found
    local    function test() return string.find(input, delimiter, pos, true) end
    local tmp1,tmp2 = test();
    for st,sp in function() return string.find(input, delimiter, pos, true) end do
        table.insert(arr, string.sub(input, pos, st - 1))
        pos = sp + 1
    end
    table.insert(arr, string.sub(input, pos))
    return arr
end

local arr = split(str,delStr);
local tm = table.insert( arr, "123")

字符串分割选自 cocos中的function.lua函数

下一篇介绍 for <var_list> in <exp_list> do end 语法使用。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值