【德州扑克开发记录】lua提取字符串中的中英文

local tb = {}
local lenInByte = #str
local i = 1
while i < (lenInByte + 1) do
local curByte = string.byte(str, i)
local szType
local byteCount=1
if curByte>0 and curByte<=127 then
if curByte>=48 and curByte<=57 then
szType = 'num'
elseif (curByte>=97 and curByte<=122) or
(curByte>=65 and curByte<=90) then
szType = 'letter'
end
byteCount = 1
elseif curByte>=192 and curByte<223 then
byteCount = 2
elseif curByte>=224 and curByte<239 then
byteCount = 3
elseif curByte>=240 and curByte<=247 then
byteCount = 4
end

local char = string.sub(str, i, i+byteCount-1)
i = i + byteCount

local item = {}
if byteCount == 1 then
item.type = szType and szType or "en"
else
item.type = "cn"
end

item.value = char

table.insert(tb, item)
end
posted @ 2016-04-19 12:13  银龙背上的骑士  阅读(355)  评论(0编辑  收藏  举报