亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

將CString字符串輸入轉(zhuǎn)化成整數(shù)的實(shí)現(xiàn)方法

 更新時間:2016年09月25日 20:33:34   投稿:jingxian  
下面小編就為大家?guī)硪黄獙String字符串輸入轉(zhuǎn)化成整數(shù)的實(shí)現(xiàn)方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

如下所示:

BOOL IsHexFormat(LPCTSTR pStr) 
{ 
  if (pStr[0] == L'0' && ((pStr[1] == L'x') || (pStr[1] == L'X'))){ 
    return TRUE; 
  } 
  return FALSE; 
} 
 
BOOL IsInputValid(LPCTSTR pStr) 
{ 
  int i; 
  BOOL res; 
  BOOL IsHex; 
  i = 0; 
  res = TRUE; 
  IsHex = IsHexFormat(pStr); 
  while (pStr[i] != L'\0'){ 
    if (pStr[i] >= L'0' && pStr[i] <= L'9'){ 
      i++; 
      continue; 
    } 
    else if (IsHex && (i == 1)){ 
      i++; 
      continue; 
    } 
    else if (IsHex &&  
        ((pStr[i] >= L'a' && pStr[i] <= L'f') ||  
         (pStr[i] >= L'A' && pStr[i] <= L'F') )) { 
      i++; 
      continue; 
    } 
    else{ 
      res = FALSE; 
      break; 
    } 
  } 
  return res; 
} 
 
UINT32 CStrHex2Uint32(LPCTSTR pStr) 
{ 
  int i = 0; 
  UINT32 res = 0; 
 
  while (pStr[i] != L'\0'){ 
    if (pStr[i] >= L'0' && pStr[i] <= L'9'){ 
      res = res * 16 + pStr[i] - L'0'; 
    } 
    else if (pStr[i] >= L'a' && pStr[i] <= L'f'){ 
      res = res * 16 + pStr[i] - L'a' + 10; 
    } 
    else if (pStr[i] >= L'A' && pStr[i] <= L'F'){ 
      res = res * 16 + pStr[i] - L'A' + 10; 
    } 
    else{ 
      break; 
    } 
    i++; 
  } 
  return res; 
} 
/* 將CString轉(zhuǎn)化成UINT32, 0x開頭的識別成十六進(jìn)制,其它為十進(jìn)制*/ 
BOOL CStr2Uint32(CString str, UINT32 *pData) 
{ 
  LPCTSTR pStr; 
  pStr = (LPCTSTR)str; 
  if (!IsInputValid(pStr)){ 
    *pData = 0; 
    return FALSE; 
  } 
  if (IsHexFormat(pStr)){ 
    UINT32 Data; 
    pStr = &pStr[2]; 
    *pData = CStrHex2Uint32(pStr); 
  } 
  else{ 
    *pData = _wtoi((wchar_t *)pStr); 
  } 
  return TRUE; 
} 

以上就是小編為大家?guī)淼膶String字符串輸入轉(zhuǎn)化成整數(shù)的實(shí)現(xiàn)方法的全部內(nèi)容了,希望對大家有所幫助,多多支持腳本之家~

相關(guān)文章

最新評論