C++里怎样判断字符串中含有汉字

2025-05-07 23:25:07
推荐回答(2个)
回答1:

//返回0:无中文,返回1:有中文
int IncludeChinese(char *str)
{
   int nRet = 0;
   char c;
   while(c=*str++)
   {
  //如果字符高位为1且下一字符高位也是1则有中文字符
  if( (c&0x80) && (*str & 0x80) )
  {
  nRet = 1;
  break;
  }
   }
   return nRet;
}

回答2:

用正则表达式,对应的库,有BOOST,还有C++11都有