判斷一行字符串中是否包含半個中文(包含Unicode總數 爲奇數)

bool IsHalfUnicode(CString strText)
{
  const char* szStrText = (LPCTSTR)strText;
  LPCTSTR  p=  szStrText;
 
  int nCount = 0;
  int nFonts = strText.GetLength();
  int nUnicode = 0;

  //是否爲偶數個數
  int nEven = nFonts%2;
  bool bResult = false;

  while( nFonts)
  {  
   if( p[0] > 0 && p[0] <= 127)  
   {  
    if( p[0] >= 0x30 && p[0] <= 0x39)  
    {  
       //是數字  
    ++nCount;
    }  
    else if( (p[0] >= 0x41 && p[0] <= 0x5a) || (p[0] >= 0x61 && p[0] <= 0x7a) ) 
    {  
      //是字母
   ++nCount;
    }  
   }
   //雙字節
   else
   {
         ++nUnicode;
   }

   ++p;
   --nFonts;
  }

  //數據全部爲ascil
  if (nCount == nFonts)
  {
      bResult = true;
  }
  //數據全部爲unicode
  else if (nFonts == nUnicode)
  {
      if ( nEven != 0)
   bResult = false;
  }
  //混合
  else
  {
   if (nUnicode %2)
    bResult = true;
  }

   return bResult;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章