我是靠谱客的博主 英俊手链,最近开发中收集的这篇文章主要介绍lua单个切割,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

local function split(input)
         local list = {}
         local len  = string.len(input)
         local index = 1
         while index <= len do
            local c = string.byte(input, index)
            local offset = 1
            if c < 0xc0 then
                offset = 1
            elseif c < 0xe0 then
                offset = 2
            elseif c < 0xf0 then
                offset = 3
            elseif c < 0xf8 then
                offset = 4
            elseif c < 0xfc then
                offset = 5
            end
            local str = string.sub(input, index, index+offset-1)
            -- print(str)
            index = index + offset
            table.insert(list, {byteNum = offset, char = str})
         end

         return list

    end


--utf8字符串分割为单个字符
function utf8StringSplit( str )
    local strTable = {}
    for uchar in string.gfind(str, "[%z1-127194-244][128-191]*") do
        strTable[#strTable+1] = uchar
    end
    return strTable
end

最后

以上就是英俊手链为你收集整理的lua单个切割的全部内容,希望文章能够帮你解决lua单个切割所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(68)

评论列表共有 0 条评论

立即
投稿
返回
顶部