void CheckString( CString str )
{
BOOL bIsDigit = TRUE;
int nCount = str.GetLength(); // 獲得字符個數
for ( int i = 0; i < nCount; i ++ )
{
if ( 0 == isdigit( str.GetAt(i) ) ) // 不是數字就置標志位
{
bIsDigit = FALSE;
break;// 退出
}
}
if ( bIsDigit ) //如果始終是,那么表示全是數字,給予提示
{
::MessageBox( NULL, TEXT("Is Digit"), NULL, NULL );
}
}
轉自:http://zhidao.baidu.com/question/56928981.html?an=0&si=1
函數 isdigit 返回值為0代表字符串存在,相反不為0代表數字。