linux c++如何判断字符串是中文还是英文
1个回答
展开全部
#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;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询