您的位置:首页 > 其它

根据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;
}
本函数转自网络。项目中遇到此需求,特此记录。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: