简介:
使用CString的的成员函数SpanIncluding进行判断。
示例代码:
#include <iostream>
#inclde <atlstr.h>
using namespace std;
//by zhaocl
int main()
{
CString strSouce = "zhaocl777",strLoad;
strSouce = strSouce.Trim();
if(strLoad = strSouce.SpanIncluding(_T("0123456789")),strLoad == strSouce && !strLoad.IsEmpty())
{
cout<<"all number."<<endl;
}
else
{
cout<<"not all number."<<endl;
}
return 0;
}
注意事项:
1、需要去除头尾空格,否则判断会错误
2、对于空字符串的判断,这里认为不符合要求即不是纯数字
3、如果源字符串中包含空格,需要在要判断的字符串中添加上空格:" 0123456789"