码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2016-04-19 13:43:43      阅读:170      评论:0      收藏:0      [点我收藏+]

标签:

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

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

标签:

原文地址:http://www.cnblogs.com/alphaGo/p/5407666.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!