cocos2d-Lua

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

2018-11-15  本文已影响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
上一篇 下一篇

猜你喜欢

热点阅读