C++ 字符函数库cctype

来源:互联网 发布:双色球软件哪个好 编辑:程序博客网 时间:2024/05/15 23:46

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:


  函数名称            

返回值

 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:
tolowerConvert uppercase letter to lowercase (function)
toupperConvert 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 valuescharactersiscntrlisspaceisupperislowerisalphaisdigitisxdigitisalnumispunctisgraphisprint0x00 .. 0x08

NUL, (other control

codes)

x          0x09 .. 0x0D

(white-space control

codes:

'/t','/f','/v','/n','/r')

xx         0x0E .. 0x1F(other control codes)x          0x20space (' ') x        x0x21 .. 0x2F!"#$%&'()*+,-./        xxx0x30 .. 0x3901234567890     xxx xx0x3a .. 0x40:;<=>?@        xxx0x41 .. 0x46ABCDEF  x x xx xx0x47 .. 0x5AGHIJKLMNOPQRSTUVWXYZ  x x  x xx0x5B .. 0x60[/]^_`        xxx0x61 .. 0x66abcdef   xx xx xx0x67 .. 0x7Aghijklmnopqrstuvwxyz   xx  x xx0x7B .. 0x7E{|}~        xxx0x7F(DEL)x          


The characters in the extended character set (above 0x7F) may belong to diverse categories depending on the locale and the platform. As a general rule, ispunct, isgraph and isprint return true on these for the standard C locale on most platforms supporting extended character sets.
http://www.cplusplus.com/reference/clibrary/cctype/
原创粉丝点击