c++——字串 ASCII碼 數字字串

來源:互聯網
上載者:User

標籤:count()   ret   處理   字母   c++   oid   class   dex   turn   

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;

 

c++——字串 ASCII碼 數字字串

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.