美文网首页cocos2d-Lua
cocos2d-x lua 3.16 分割字符串 阶梯字符串

cocos2d-x lua 3.16 分割字符串 阶梯字符串

作者: 人气小哥 | 来源:发表于2018-11-15 14:09 被阅读0次

utf8函数参考 https://www.jianshu.com/p/7fc11879b575

--[[
拆分字符串
s='1234abcd'
-- 拆分成{"1","2","3","4","a","b","c","d"}
]]
function g_splitString(_str)
    local tbList = {}
    for i = 1, string.utf8len(_str) do
        tbList[i]=string.utf8sub(_str,i,i)
    end

    -- for i=1,k do
    --  print(tbList[i])
    -- end
    return tbList
end

--[[
拆分梯形字符串
local s = "你1好2aa世界"
-- 拆分成
tb = {
    "你",
    "你1",
    "你1好",
    "你1好2",
    "你1好2a",
    "你1好2aa",
    "你1好2aa世",
    "你1好2aa世界",
}
]]
function g_splitTrapezoidString(_str)
    local tbList = {}
    for i = 1, string.utf8len(_str) do
        tbList[i]=string.utf8sub(_str,1,i)
    end

    -- for i=1,k do
    --  print(tbList[i])
    -- end
    return tbList
end

相关文章

网友评论

    本文标题:cocos2d-x lua 3.16 分割字符串 阶梯字符串

    本文链接:https://www.haomeiwen.com/subject/ufryfqtx.html