#include <iostream>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
/***linux下一个中文占用三个字节,windows占两个字节***/
void chinese_or_english(char *str)
{
char chinese[4] = {0};
for (int i = 0; i < strlen(str); i++) {
//if (str[i] >= 0 && str[i] <= 127) { //ascII
if ((str[i] & 0x80) == 0) { //chinese:the top is 1
cout<<"alpha:"<<str[i]<<endl;
}
//else if (str[i] < 0){
else {
chinese[0] = str[i];
chinese[1] = str[i + 1];
chinese[2] = str[i + 2];
i++; //skip one more
i++;
printf("chinese:%s\n", chinese);
}
}
}
int main()
{
char str[] = "tai太阳yang";
cout<<strlen(str)<<endl;
chinese_or_english(str);
return 0;
}
判断占用字节数。
int SVPSettingKeyboard::chinese_or_english(std::string str,int index)
{
if(index > str.size()-1)
return 0;
if((str[index-1]& 0x80) == 0){
return 1;
}else{
int n = 2;
while(((str[index-n] &0x80) == 0x80 )&&((str[index-n] &0x40) == 0)){
++n;
}
return n;
}
}
原文链接: https://www.cnblogs.com/yuguangyuan/p/8809137.html
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍
原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/272206
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!