cctype (ctype.h)
<C++ Primer 第四版> 3.2.4 节 string 对象中字符的处理
<C++ Primer Plus 第五版> 6.3 节 字符函数库 cctype(比前者多个isblank介绍, 比较详细)
header
Character handling functions
This header declares a set of functions to classify and transform individual characters.
All these functions take as parameter the int equivalent of one character and return an int, that can either be another character or a value representing a boolean value: an int value of 0 means false, and an int value different from 0 represents true.
There are two sets of functions:
First a set of classifying functions that check whether the character passed as parameter belongs to a certain category. These are:
All these functions take as parameter the int equivalent of one character and return an int, that can either be another character or a value representing a boolean value: an int value of 0 means false, and an int value different from 0 represents true.
There are two sets of functions:
First a set of classifying functions that check whether the character passed as parameter belongs to a certain category. These are:
函数名称 | 返回值 |
isalnum() | 如果参数是字母数字, 即字母或数字, 该函数返回 true |
isalpha() | 如果参数是字母, 该函数返回 true |
isblank() | 如果参数是空格或水平制表符, 该函数返回 true |
iscntrl() | 如果参数是控制字符, 该函数返回 true |
isdigit() | 如果参数是数字 (0~9), 该函数返回 true |
isgraph() | 如果参数是除空格之外的打印字符, 该函数返回 true |
isprint() | 如果参数是打印字符 (包括空格), 该函数返回 true |
ispunct() | 如果参数是标点符号, 该函数返回 true |
isspace() | 如果参数是标准空白字符, 如空格、进纸、换行符、回车、水平制表符或垂直制表符, 该函数返回 true |
islower() | 如果参数是小写字母, 该函数返回 true |
isupper() | 如果参数是大写字母, 该函数返回 true |
isxidgit() | 如果参数是十六进制的数字, 即 0~9, a~f 或 A~F, 该函数返回 true |
(C++ Primer Plus 第五版)
And secondly, two functions to convert between letter cases:
tolower | Convert uppercase letter to lowercase (function) |
toupper | Convert lowercase letter to uppercase (function) |
For the first set, here is a map of how the original 127-character ASCII set is considered by each function (an x indicates that the function returns true on that character)
ASCII values | characters | iscntrl | isspace | isupper | islower | isalpha | isdigit | isxdigit | isalnum | ispunct | isgraph | isprint |
---|---|---|---|---|---|---|---|---|---|---|---|---|
0x00 .. 0x08 | NUL, (other control codes) | x | ||||||||||
0x09 .. 0x0D | (white-space control codes: '/t','/f','/v','/n','/r') | x | x | |||||||||
0x0E .. 0x1F | (other control codes) | x | ||||||||||
0x20 | space (' ') | x | x | |||||||||
0x21 .. 0x2F | !"#$%&'()*+,-./ | x | x | x | ||||||||
0x30 .. 0x39 | 01234567890 | x | x | x | x | x | ||||||
0x3a .. 0x40 | :;<=>?@ | x | x | x | ||||||||
0x41 .. 0x46 | ABCDEF | x | x | x | x | x | x | |||||
0x47 .. 0x5A | GHIJKLMNOPQRSTUVWXYZ | x | x | x | x | x | ||||||
0x5B .. 0x60 | [/]^_` | x | x | x | ||||||||
0x61 .. 0x66 | abcdef | x | x | x | x | x | x | |||||
0x67 .. 0x7A | ghijklmnopqrstuvwxyz | x | x | x | x | x | ||||||
0x7B .. 0x7E | {|}~ | x | x | x | ||||||||
0x7F | (DEL) | x |