linux c++如何判断字符串是中文还是英文
答案:1 悬赏:70 手机版
解决时间 2021-03-03 20:43
- 提问者网友:浩歌待明月
- 2021-03-03 17:31
linux c++如何判断字符串是中文还是英文
最佳答案
- 五星知识达人网友:洒脱疯子
- 2021-03-03 18:08
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
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;
}
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
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;
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯