ctype中的各种函数 Character handling functions

来源:互联网 发布:system01.dbf数据大 编辑:程序博客网 时间:2024/06/05 05:07

<cctype> (ctype.h)

isalnum

是否是字母或者数字
Check if character is alphanumeric
Checks whether c is either a decimal digit or an uppercase or lowercase letter.

    /* isalnum example */#include <stdio.h>#include <ctype.h>int main (){  int i;  char str[]="c3po...";  i=0;  while (isalnum(str[i])) i++;  printf ("The first %d characters are alphanumeric.\n",i);  return 0;}Output:The first 4 characters are alphanumeric.

isalpha

是否是字母

       /* isalpha example */    #include <stdio.h>    #include <ctype.h>    int main ()    {      int i=0;      char str[]="C++";      while (str[i])      {        if (isalpha(str[i])) printf ("character %c is alphabetic\n",str[i]);        else printf ("character %c is not alphabetic\n",str[i]);        i++;      }      return 0;    }    Output:    character C is alphabetic    character + is not alphabetic    character + is not alphabeti

isblank

是否是空格
Check if character is blank
Checks whether c is a blank character.

A blank character is a space character used to separate words within a line of text.

The standard “C” locale considers blank characters the tab character (‘\t’) and the space character (’ ‘).

Other locales may consider blank a different selection of characters, but they must all also be space characters by isspace.

For a detailed chart on what the different ctype functions return for each character of the standard ASCII character set, see the reference for the header.

In C++, a locale-specific template version of this function (isblank) exists in header .

Compatibility note: Standardized in C99 (C++11).

 /* isblank example */#include <stdio.h>#include <ctype.h>int main (){  char c;  int i=0;  char str[]="Example sentence to test isblank\n";  while (str[i])  {    c=str[i];    if (isblank(c)) c='\n';    putchar (c);    i++;  }  return 0;}This code prints out the C string character by character, replacing any blank character by a newline character. Output:Examplesentencetotestisblank

iscntrl

是否是控制符(0-31,127)
Check if character is a control character
Checks whether c is a control character.
A control character is a character that does not occupy a printing position on a display (this is the opposite of a printable character, checked with isprint).
For the standard ASCII character set (used by the “C” locale), control characters are those between ASCII codes 0x00 (NUL) and 0x1f (US), plus 0x7f (DEL).
For a detailed chart on what the different ctype functions return for each character of the standard ANSII character set, see the reference for the header.
In C++, a locale-specific template version of this function (iscntrl) exists in header .

isdigit

是否是数字
/* isdigit example */
#include

isgraph

是否是图形化字符(大于31除开127,不包含空格)
Check if character has graphical representation
Checks whether c is a character with graphical representation.

The characters with graphical representation are all those characters than can be printed (as determined by isprint) except the space character (' ').For a detailed chart on what the different ctype functions return for each character of the standard ASCII character set, see the reference for the <cctype> header.In C++, a locale-specific template version of this function (isgraph) exists in header <locale>.

islower

Check if character is lowercase letter

isprint

是否可打印(大于31除开127,包括空格)
Check if character is printable
Checks whether c is a printable character.

A printable character is a character that occupies a printing position on a display (this is the opposite of a control character, checked with iscntrl).

For the standard ASCII character set (used by the “C” locale), printing characters are all with an ASCII code greater than 0x1f (US), except 0x7f (DEL).

isgraph returns true for the same cases as isprint except for the space character (’ ‘), which returns true when checked with isprint but false when checked with isgraph.

For a detailed chart on what the different ctype functions return for each character of the standard ANSII character set, see the reference for the header.

In C++, a locale-specific template version of this function (isprint) exists in header .

ispunct

是否是标点符号(isgraph中除开字母和数字)
Check if character is a punctuation character
Checks whether c is a punctuation character.

The standard “C” locale considers punctuation characters all graphic characters (as in isgraph) that are not alphanumeric (as in isalnum).

Other locales may consider a different selection of characters as punctuation characters, but in any case they are isgraph but not isalnum.

For a detailed chart on what the different ctype functions return for each character of the standard ANSII character set, see the reference for the header.

In C++, a locale-specific template version of this function (ispunct) exists in header .

isspace

是否是空格
Check if character is a white-space
Checks whether c is a white-space character.

For the “C” locale, white-space characters are any of:
’ ’ (0x20) space (SPC)
‘\t’ (0x09) horizontal tab (TAB)
‘\n’ (0x0a) newline (LF)
‘\v’ (0x0b) vertical tab (VT)
‘\f’ (0x0c) feed (FF)
‘\r’ (0x0d) carriage return (CR)

Other locales may consider a different selection of characters as white-spaces, but never a character that returns true for isalnum.

For a detailed chart on what the different ctype functions return for each character of the standard ASCII character set, see the reference for the header.

In C++, a locale-specific template version of this function (isspace) exists in header .

isupper

Check if character is uppercase letter

isxdigit

是否是16进制
Check if character is hexadecimal digit

tolower

Convert uppercase letter to lowercase

toupper

Convert lowercase letter to uppercase

附:
title
title