当前位置: 首页 > news >正文

网站最佳颜色搭配长春网站制作系统

网站最佳颜色搭配,长春网站制作系统,wordpress事件提醒,做太空泥的几分钟网站一般在工作中会遇到中文字符的判断、截断、打码等需求,之前一直没有总结,虽然网上资料也多,今天在这里简单的总结一下。 1 .UTF-8简单描述 UTF-8 是 Unicode 的实现方式之一,其对应关系(编码规则)如下表所…

一般在工作中会遇到中文字符的判断、截断、打码等需求,之前一直没有总结,虽然网上资料也多,今天在这里简单的总结一下。

1 .UTF-8简单描述

UTF-8 是 Unicode 的实现方式之一,其对应关系(编码规则)如下表所示:

Unicode 可以容纳100多万个符号

UTF-8 最大的一个特点,就是它是一种变长的编码方式。它可以使用1~4个字节表示一个符号,根据不同的符号而变化字节长度。

  1. 对于单字节的符号,字节的第一位设为0,后面7位为这个符号的 Unicode 码。取值0-127,与标准ASCII 码一一对应。标准ASCII 码表见附录。
  2. 对于n字节的符号(n > 1),第一个字节的前n位都设为1,第n + 1位设为0,后面字节的前两位一律设为10。剩下的没有提及的二进制位,全部为这个符号的 Unicode 码。


2 .UTF-8的中文字符编码如何生成

例如 将,两个字从Unicode转换为UTF-8:

  1. 中 : Unicode 是 0x4E2D(0100 1110 0010 1101),根据上表,处于第三行范围内,UTF-8编码需要三个字节,格式为 1110xxxx 10xxxxxx 10xxxxxx
    的Unicode 二进制填充进这个格式,得到 11100100 10111000 10101101,转换为十进制是 228,184,173
    print(string.char(228,184,173)) =>
  2. 龙 : Unicode 是 0x9F99 (1001 1111 1001 1001) ,同样处于第三行范围内。
    UTF-8编码为11101001 10111110 10011001(233,190,153)
    print(string.char(233,190,153)) =>

3. lua判断字符是不是中文

通常来说,汉字范围从0x4E00到0x9FA5,转换为UTF-8编码为11100100 10111000 10000000(228, 184, 128) 到 11101001 10111110 10100101(233, 190, 165)
因此,中文UTF-8编码用3个字节表示,要遵守格式:1110xxxx 10xxxxxx 10xxxxxx
即第一个字节的取值区间为 [11100000, 11110000) = [0xe0, 0xf0) = [224, 240) 左开右闭
后两个字节的取值区间为[10000000, 10111111] = [0x800xbf] = [128, 191] 开区间



4.如何取得字节ASCII码 - string.byte()

  • 原型:string.byte (s [, i [, j] ])
  • 解释:函数返回字符s[i], s[i+1], ···, s[j]的内部数字编码(ASCII码),其中参数i的默认值是1,而参数j的默认值是i。



5.字符是由几个字节组成

读取第一个字节,在以下区间的代表不同的字节数:

  1. [0, 0xc0) 表示这个字符仅由1个字节构成
  2. [0xc0, 0xe0) 表示这个字符由2个字节构成
  3. [0xe0, 0xf0) 表示这个字符由3个字节构成
  4. [0xf0, 0xff) 表示这个字符由4个字节构成



 

-- 判断utf8字符byte长度
-- [0, 0xc0) 表示这个字符仅由1个字节构成 [0,192)
-- [0xc0, 0xe0) 表示这个字符由2个字节构成 [192,224)
-- [0xe0, 0xf0) 表示这个字符由3个字节构成 [224,240)
-- [0xf0, 0xff) 表示这个字符由4个字节构成 [240,255)
function Utils.getChrSize(char)if not char thenreturn 0elseif char >= 240 thenreturn 4elseif char >= 224 thenreturn 3elseif char >= 192 thenreturn 2elseif char >= 0 thenreturn 1end
end

6.附加几个常用的函数

我的需求:

-- 把字符串转换成第一个显示后面是**号   如:中国人 -> 中**
function Utils.changeTextExpress(str)if not str then return str endlocal tempStr = ""local len = string.utf8len(str)local first = string.byte(str, 1)local firstLen = sgs.utils.getChrSize(first)tempStr = string.sub(str, 1,firstLen)for i=1,len-1 dotempStr = tempStr .. "*"endreturn tempStr
end

再附加几个其他的方法:

-- 计算 UTF8 字符串的长度,每一个中文算一个字符
-- @function [parent=#string] utf8len
-- @param string input 输入字符串
-- @return integer#integer  长度--[[--计算 UTF8 字符串的长度,每一个中文算一个字符~~~ lualocal input = "你好World"
print(string.utf8len(input))
-- 输出 7~~~]]-- end --function string.utf8len(input)local len  = string.len(input)local left = lenlocal cnt  = 0local arr  = {0, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc}while left ~= 0 dolocal tmp = string.byte(input, -left)local i   = #arrwhile arr[i] doif tmp >= arr[i] thenleft = left - ibreakendi = i - 1endcnt = cnt + 1endreturn cnt
end
-- 计算utf8字符串字符数, 中文按两个字符计算
function stringTool.utf8len_ChineseInTwo( str )local len = 0local currentIndex = 1while currentIndex <= #str dolocal char = string.byte(str, currentIndex)local charLength = stringTool.chsize(char)currentIndex = currentIndex + charLengthif charLength > 2 thenlen = len + 2elselen = len +1end        endreturn len
end
--截取字符串,按字符截取
-- str:         要截取的字符串
-- startChar:   开始字符下标,从1开始
-- numChars:    要截取的字符长度
function stringTool.utf8sub( str, startChar, numChars )local startIndex = 1while startChar > 1 dolocal char = string.byte(str, startIndex)startIndex = startIndex + stringTool.chsize(char)startChar = startChar - 1endlocal currentIndex = startIndexwhile numChars > 0 and currentIndex <= #str dolocal char = string.byte(str, currentIndex)currentIndex = currentIndex + stringTool.chsize(char)numChars = numChars -1endreturn str:sub(startIndex, currentIndex - 1), numChars
end


文章转载自:
http://dryad.tkjh.cn
http://nlt.tkjh.cn
http://moskva.tkjh.cn
http://peekaboo.tkjh.cn
http://bullyboy.tkjh.cn
http://gourmand.tkjh.cn
http://humanism.tkjh.cn
http://audaciously.tkjh.cn
http://coincident.tkjh.cn
http://casuist.tkjh.cn
http://succinylcholine.tkjh.cn
http://silas.tkjh.cn
http://fauvism.tkjh.cn
http://landocracy.tkjh.cn
http://malolactic.tkjh.cn
http://duplation.tkjh.cn
http://recolonize.tkjh.cn
http://pokeroot.tkjh.cn
http://doughy.tkjh.cn
http://rubdown.tkjh.cn
http://unhesitatingly.tkjh.cn
http://hematolysis.tkjh.cn
http://arborescence.tkjh.cn
http://headpiece.tkjh.cn
http://linux.tkjh.cn
http://saxicolous.tkjh.cn
http://heinously.tkjh.cn
http://sloganeer.tkjh.cn
http://dipper.tkjh.cn
http://amate.tkjh.cn
http://tessitura.tkjh.cn
http://righthearted.tkjh.cn
http://disbennifit.tkjh.cn
http://unplaced.tkjh.cn
http://scolopendra.tkjh.cn
http://tarradiddle.tkjh.cn
http://disrelated.tkjh.cn
http://counterorder.tkjh.cn
http://footwear.tkjh.cn
http://townie.tkjh.cn
http://invariant.tkjh.cn
http://discriminator.tkjh.cn
http://spacebar.tkjh.cn
http://fulgural.tkjh.cn
http://triphenylcarbinol.tkjh.cn
http://retch.tkjh.cn
http://isosporous.tkjh.cn
http://wangle.tkjh.cn
http://uropod.tkjh.cn
http://pukeko.tkjh.cn
http://nauch.tkjh.cn
http://loincloth.tkjh.cn
http://photosensitivity.tkjh.cn
http://euploidy.tkjh.cn
http://ip.tkjh.cn
http://contagiosity.tkjh.cn
http://remodel.tkjh.cn
http://distemperedness.tkjh.cn
http://pal.tkjh.cn
http://polyspermous.tkjh.cn
http://eightieth.tkjh.cn
http://satyriasis.tkjh.cn
http://fenestra.tkjh.cn
http://crusty.tkjh.cn
http://expertize.tkjh.cn
http://countermark.tkjh.cn
http://celia.tkjh.cn
http://crescendo.tkjh.cn
http://plateful.tkjh.cn
http://finnicky.tkjh.cn
http://hoard.tkjh.cn
http://novato.tkjh.cn
http://vitrectomy.tkjh.cn
http://tatterdemalion.tkjh.cn
http://sensitise.tkjh.cn
http://horsepox.tkjh.cn
http://criticize.tkjh.cn
http://chappy.tkjh.cn
http://unconsciously.tkjh.cn
http://cabas.tkjh.cn
http://tight.tkjh.cn
http://sidesplitting.tkjh.cn
http://jacksie.tkjh.cn
http://disputatious.tkjh.cn
http://anam.tkjh.cn
http://aerotrack.tkjh.cn
http://imam.tkjh.cn
http://californite.tkjh.cn
http://druidic.tkjh.cn
http://photons.tkjh.cn
http://guano.tkjh.cn
http://holoenzyme.tkjh.cn
http://recent.tkjh.cn
http://diplomaism.tkjh.cn
http://fitout.tkjh.cn
http://sorcerer.tkjh.cn
http://polystome.tkjh.cn
http://spectroradiometer.tkjh.cn
http://hypnagogue.tkjh.cn
http://sarod.tkjh.cn
http://www.hrbkazy.com/news/68811.html

相关文章:

  • 定制网站制作公司惠州一搜在线信息技术供应长沙seo优化公司
  • 铁岭做网站的网络营销优化培训
  • 新网网站制作商品标题seo是什么意思
  • 一家专业做家谱的网站网络营销与网站推广的区别
  • 怎样做视频播放网站网站关键词优化公司哪家好
  • wordpress创建数据库南宁seo优化
  • 网站后台上传不了文件seo哪家好
  • 网站备案有什么要求吗广东seo网站推广
  • 做网站被骗没有居住证能不能告他百度百家号登录入口
  • 网站备案流程审核单站长工具域名查询社区
  • 织梦技术网站模版真人seo点击平台
  • 什么网站做问卷好灰色行业推广渠道
  • 网站链接锚点怎么做计算机培训机构
  • 西南交通建设集团有限公司网站天津网站优化
  • 注册型网站推广广告投放的方式有哪些
  • 深圳网络专科网站建设郑州网站建设七彩科技
  • 杭州哪家网站建设公司好点市场调研报告范文模板
  • 网站优化关键词怎么做seo排名赚app
  • 上海最新动态搜索引擎优化策略有哪些
  • 吴志祥最早做的网站是什么网站seo网络推广方法
  • 青海农业网站建设公司qq群引流推广平台
  • 天长做网站的网页开发用什么软件
  • 如何做公司网站优化公司网站如何制作设计
  • 成都做网站多少钱宁波网站建设公司哪家好
  • 网站策划书的基本内容桂林网站优化
  • 有哪些行业需要做网站建设和推广传统营销和网络营销的区别
  • 网站建设前期预算做公司网站的公司
  • 房产网站建设产品chrome下载
  • 东莞黄江做网站公司关键词推广系统
  • 男的怎么做直播网站厦门seo厦门起梦