根据utf8字符首字节,获取utf8字符所占字节数
2018-02-05 10:11
246 查看
//根据utf8字符的首字节,获取utf8字符所占字节数 static uint8_t GetUtf8charByteNum(unsigned char ch) { uint8_t byteNum = 0; if (ch >= 0xFC && ch < 0xFE) byteNum = 6; else if (ch >= 0xF8) byteNum = 5; else if (ch >= 0xF0) byteNum = 4; else if (ch >= 0xE0) byteNum = 3; else if (ch >= 0xC0) byteNum = 2; else if (0 == (ch & 0x80)) byteNum = 1; return byteNum; }本函数转自网络。项目中遇到此需求,特此记录。
相关文章推荐
- 根据字符长度来获取字节数
- 根据字节数获取字符长度 并截取
- [C++]_[获取Utf8字符串的字符个数和子字符串]
- Qt中QFtp获取带有中文的文件名称出现乱码的解决方法(比较巧妙,toLatin1压缩掉了QString自动给每个英文字符加上的那些00字节)
- .net 根据图片网络地址获取图片二进制字节数据流
- 让MySql支持表情符号(MySQL中4字节utf8字符保存方法)
- Android根据字符串型的资源名获取对应资源id
- 获取字符串中的数字、符号、中文、英文单词、字母、空格、字节、其他字符的个数
- 让MySql支持Emoji表情(MySQL中4字节utf8字符保存方法)
- encode_utf8 把字符编码成字节 decode_utf8解码UTF-8到字符
- delphi 获取一个字符占用几个字节,方法
- encode_utf8 把字符编码成字节 decode_utf8解码UTF-8到字符
- 获取字符窜的字节长度
- MySQL字符编码的讨论:如何处理emoji等4字节的Unicode字符 - utf8mb4 vs. utf8 Collations
- iOS开发-NSString小拓展-判断是否纯中文-获取字符所占字节
- JAVA获取字符、字节长度(适合Mysql)
- encode_utf8 把字符编码成字节 decode_utf8解码UTF-8到字符
- javascript获取字符的字节长度
- 获取字符的字节长度, 获取中英文的字符字节长度
- 过滤utf8 字符中超过三个字节的字符,或者非utf8字符