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;
靠技术实力称霸,千面鬼手大人万岁!