c++——字符串 ASCII码 数字字符串

size_t CMyStr::_myStrlen(char const * srcStr)
    {
        size_t len = 0;
        if (srcStr != NULL)
        {
            while (*(srcStr + len) != '\0')
            {
                len++;
            }
        }
        return len;
    } //字符串的最后为'\0'的问题,字符串的长度包括'\0'

 

    //字符串之数字处理
    CMyStr(int i)
    {
        int tempVal = i;
        bool isFu = false;
        if (tempVal < 0)
        {
            len = 2; // \0  -号
            isFu = true;
            tempVal = -tempVal;
        }
        else
            len = 1; // \0
        while (tempVal)
        {
            tempVal /= 10;
            len++;
        }
        pStr = new char[len];
        *(pStr + len - 1) = '\0';
        if (ifFul)
        {
            tempVal = -i;
        }
        else
            tempVal = i;
        int index = 0;
        while (tempVal)
        {
            int temp = tempVal % 10;
            *(pStr + len - 2 - index) = temp + '0'; //转换为字符类型
            tempVal /= 10;
            index++;
        }
        if (isFu)
            *pStr = '-';
    }

 

    //字母ASCII码  A--65  a--97
    char *str;
    int counter[26];
    void doc::count()
    {
        for (int i = 0; i < length; i++)
        {
            if (str[i] >= 'a' && str[i] <= 'z')
                counter[str[i] - 'a']++;
            if (str[i] >= 'A' && str[i] <= 'Z')
                counter[str[i] - 'A']++;
        }
        for (int index = 0; index < 26; ++index)
            cout << (char)(index + 65) << " or " << (char)(index + 97) << " 出现的次数是:" << counter[index] << endl;

 

posted @ 2017-10-05 13:47  千面鬼手大人  阅读(5601)  评论(0编辑  收藏  举报
// 侧边栏目录 // https://blog-static.cnblogs.com/files/douzujun/marvin.nav.my1502.css