c++ 判断字符串只包含字母、数字、汉字

来源:互联网 发布:零基础java就业班 编辑:程序博客网 时间:2024/05/18 01:15

bool StringUtils::CheckName(const char * iName){ 
 bool result=false;
 if(strlen(iName)>62)return result;//长度不能超过62个字符
 while(*iName)
 {
  if((*iName)&0x80){
   //是汉字
   result=true;
   iName++;//知道是汉字的话跳过一个字节检测
  }
  else if((*iName>='a'&&*iName<='z'||*iName>='A'&&*iName<='Z')||((*iName)>='0'&&(*iName)<='9'))
  {
  result=true;  
  } 
  else{
  result=false;
  break;
  }
  iName++;
 }
    return result;
}

 

原创粉丝点击