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;

 

转载于:https://www.cnblogs.com/ming-michelle/p/7629093.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值