本文主要是介绍C/C++之cctype字符处理,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
文章目录
- 检查
- 转化
#include <cctype> // #include <ctype.h>
检查
| 函数 | 重点 | 功能 |
|---|---|---|
| isalnum | 字母、数字 | Check if character is alphanumeric (function ) |
| isdigit | 数字 | Check if character is decimal digit (function ) |
| isalpha | 字母 | Check if character is alphabetic (function ) |
| islower | 小写字母 | Check if character is lowercase letter (function ) |
| isupper | 大写字母 | Check if character is uppercase letter (function ) |
| isblank | Check if character is blank (function ) | |
| iscntrl | Check if character is a control character (function ) | |
| isgraph | Check if character has graphical representation (function ) | |
| isprint | Check if character is printable (function ) | |
| ispunct | Check if character is a punctuation character (function ) | |
| isspace | Check if character is a white-space (function ) | |
| isxdigit | Check if character is hexadecimal digit (function ) |
string s = "AB34cd.?";
for(char ch:s)
{cout << isalnum(ch) << " ";
}
// 1 4 2 0 0
转化
| 函数 | 重点 | 功能 |
|---|---|---|
| tolower | 大写变小写 | Convert uppercase letter to lowercase (function ) |
| toupper | 小写变大写 | Convert lowercase letter to uppercase (function ) |
string s = "AB34cd.?";
for (int i = 0; i < s.size(); i++)
{s[i] = tolower(s[i]);
}
cout << s << endl; //ab34cd.?
这篇关于C/C++之cctype字符处理的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!