//判断字符串数据是否合法
需要判断非法字符('-'、‘.' 除外)同时还需判断’-‘、’.' 在字符串中的位置, 进而判断是否合法.
{
int mCount = 0; //'-'个数
int dCount = 0; //'.'个数
int nLen = str.GetLength();
for(int i = 0;i < nLen;i++)
{
if( str.GetAt(i)=='-')
mCount++;
if( mCount > 1|| dCount > 1)
return false;
if(!(str.GetAt(i) >='0'&&str.GetAt(i) <='9' ))
{
if( str.GetAt(i)=='.'&&( i>0 && i<str.GetLength()-1))
{
dCount++;
continue;
}
else if((str.GetAt(i)=='-')&&(0==i&&str.GetAt(i+1)!='.'))
continue;
else
return false;
}
}
return true;
}