首页 > 代码库 > 表示数值的字符串

表示数值的字符串

错误的代码:

class Solution {
public:
    bool isNumeric(char* string)
    {
        if(string == NULL)
            return false;
        if(*string == + || *string == -)
            string++;
        if(*string == \0)
            return false;
        bool flag = true;
        ScanDigit(string);
        if(*string != \0){
            if(*string == .){
                string++;
                ScanDigit(string);
                if(*string == e || *string == E)
                    flag = Exponential(string+1);
            }
            else if(*string == e || *string == E)
                flag = Exponential(string+1);
            else
                flag = false;
        }
        return flag && (*string == \0);
    }
    void ScanDigit(char *string){
        while(*string >= 0 && *string <= 9 && *string != \0)
            string++;
    }
    bool Exponential(char *string){
        if(*string == + || *string == -)
            string++;
        if(*string == \0)
            return false;
        ScanDigit(string);
        if(*string == \0)
            return true;
        else
            return false;
    }
};

 

表示数值的字符串