如何判断是数字,或者是其他的字符,或者说是汉字???
解决方案 »
- 窗口为顶级窗口是什么属性?
- 哪位大侠跑通过CORBA事件服务
- 如何解决warning LNK4044: unrecognized option " "; ignored
- 从文本读出些数据,要把他们转化成数组放进二维数组应该怎么做?
- 用过BCG的朋友看看
- 一个菜鸟级问题
- 关于三次样条插值算法`
- 我使用我机器上的VC,在按钮上写汉字时汉字的表现形式是"??"?我将dialog的Properties中的language设为Chinese(P.R.C)了,这是怎么回事?
- 咨询一下,您了解软件工程硕士?您想上工程硕士吗?您今年打算上吗?
- 我新建了一个MFC类,它派生自CWnd,为什么不能用OnTimer
- Activex控件在IE中使用,内存泄漏问题已经何时销毁对象。
- 如何快捷的删除整个工程的注释?
{
if(str.IsEmpty())
return -1 ;
int nDot = 0 ;
//数值只能是0到9及小数点组成
for(int i =0 ; i < str.GetLength() ; i++ )
{
char ch = str.GetAt(i);
if('.' == ch )//小数点
{
nDot ++ ;
continue ;
}
if(ch >='0' && ch <= '9')//数字
continue ;
return -2 ;//非法字符
}
if(nDot > 1)
return -3 ;//小数点多于两个
else if(0 == nDot)
return 1 ;//整数
else if(1 == nDot)
return 0 ;//浮点数
return -1000 ;//未知错误
}
IsNumber();//判断是数字
IsCharAlpha();//判断是字符
汉字是双字节的!
IsDBCLeadByte();//判断字节是汉字的前一个还是后一个字节
...
CharNext(sss) 将获得sss的第一个字符,该字符可能是ascII或全角码字符,
然后判断这个字符的长度,大于2就是汉字或其他ucode,若是asc码,就在判断是数字或字符
(减去‘0’判断结果是否在0~9以内)
int nCharCount = 0;//字符个数
int nChineseCount = 0;//汉字个数
CString strNum = "";
CString strTemp;
for(int i = 0; i < str.GetLength(); i++)
{
if( (BYTE)str[i] < 0x80 )
{
nCharCount++;
if(str[i] >= '0' && str[i] <= '9')
{
strTemp.Format("%c", str[i]);
strNum += strTemp + " ";
}
}
else
{
nCharCount++;
nChineseCount++;
i++;
}
}
AfxMessageBox(strNum);