is,isw 常式
備註
這些常式會測試指定的條件的字元。
是常式會產生有意義的結果為 – 1 從任何整數引數 (EOF) 至 UCHAR_MAX (0xFF),內含。 預期的引數型別是int。
警告
對於是常式、 傳遞引數型別的char可能會產生無法預期的結果。SBCS 或 MBCS 半形字元的型別char值大於 0x7F 為負數。如果char是傳遞時,編譯器都可能會將值轉換為帶正負號int 、 或簽章長。這個值可能是由編譯器與未預期的結果的正負號擴展。
Isw 常式會產生有意義的結果的任何整數值,介於-1 (WEOF) 到 0xFFFF (含)。 Wint_t WCHAR 中定義資料型別。以 h 不帶正負號的短。 它可以存放任何萬用字元或寬字元結束檔案 (WEOF) 的值。
輸出值會影響的設定來LC_CTYPE類別設定的地區設定; 請參閱 setlocale 如需詳細資訊。 這些函式版本 _l 尾碼會將目前的地區設定用於這個地區設定相關的行為。 與版本 _l 尾碼完全相同,不同之處在於它們使用地區設定參數中傳遞。
在"C"地區設定中,測試條件的是常式如下:
isalnum
英數字元 (A – Z、 a – z 或 0-9)。isalpha
字母 (A – Z 或 a – z)。__isascii
ASCII 字元 (0x00 – 0x7F)。iscntrl
控制字元 (0x00 – 0x1F 或 0x7F)。__iscsym
字母、 底線或數字。__iscsymf
字母或底線。isdigit
十進位數字 (0 – 9)。isgraph
除了空格 () 的可列印字元。islower
小寫字母 (a – z)。isprint
列印的字元包括空格 (0x20 – 0x7E)。ispunct
標點符號字元。isspace
泛空白字元 (0x09-0x0D 或 0x20)。isupper
大寫字母 (A – Z)。isxdigit
十六進位數字 (A-F、 a – f,則為 0 – 9)。
對於 isw 常式,為指定的條件測試的結果是獨立的地區設定。 測試條件的 isw 函式如下:
iswalnum
iswalpha 或 iswdigit。iswalpha
寬字元會實作自訂集合的任何其中一項iswcntrl, iswdigit, iswpunct,或iswspace不是零。 iswalpha傳回非零的值只能為寬字元的iswupper或iswlower不是零。iswascii
寬字元表示的 ASCII 字元 (0x0000 – 0x007F)。iswcntrl
控制萬用字元。__iswcsym
任何萬用字元的 isalnum 為 true 或 '_' 字元。__iswcsymf
任何萬用字元的iswalpha為 true 或 '_' 字元。iswctype
字元都具有屬性所指定的desc引數。 每一個有效的值為desc引數的iswctype,沒有對等的寬字元分類的常式,如下表所示:對等關係的 iswctype ( c、 desc ) 至其他的 isw 測試常式
值的 desc 引數
iswctype ( c、 desc ) 等位
_ALPHA
iswalpha( c )
_ALPHA | _DIGIT
iswalnum( c )
_CONTROL
iswcntrl( c )
_DIGIT
iswdigit( c )
_ALPHA | _DIGIT | _PUNCT
iswgraph( c )
_LOWER
iswlower( c )
_ALPHA | _BLANK | _DIGIT | _PUNCT
iswprint( c )
_PUNCT
iswpunct( c )
_SPACE
iswspace( c )
_UPPER
iswupper( c )
_HEX
iswxdigit( c )
iswdigit
對應於十進位數字字元的萬用字元。iswgraph
可列印的寬字元,但寬字元的空間 (L' ')。iswlower
小寫字母或實作定義組寬字元的任何資料的iswcntrl, iswdigit, iswpunct,或iswspace不是零。 iswlower傳回非零值只能用於對應的寬字元為小寫字母。iswprint
可列印的寬字元,包括空格寬字元 (L' ')。iswpunct
這兩個寬字元的空間的可列印寬字元 (L' ') 或寬字元的iswalnum不是零。iswspace
寬字元相對於標準的泛空白字元或實作定義一組寬字元的其中一項是iswalnum為 false。 標準的空格字元包括: 空間 (L' '),換頁 (L '\f')、 新行 (L \n)、 換行鍵 ('\r' L)、 水平頁籤 (L '\t') 和垂直索引標籤 (L '\v')。iswupper
寬字元是大寫或實作定義一組寬字元代表的哪一個值不是iswcntrl, iswdigit, iswpunct,或iswspace不是零。 iswupper傳回非零值只能用於對應的寬字元為大寫的字元。iswxdigit
廣泛的字元相對於十六進位數字字元。
範例
// crt_isfam.c
/* This program tests all characters between 0x0
* and 0x7F, then displays each character with abbreviations
* for the character-type codes that apply.
*/
#include <stdio.h>
#include <ctype.h>
int main( void )
{
int ch;
for( ch = 0; ch <= 0x7F; ch++ )
{
printf( "%.2x ", ch );
printf( " %c", isprint( ch ) ? ch : ' ' );
printf( "%4s", isalnum( ch ) ? "AN" : "" );
printf( "%3s", isalpha( ch ) ? "A" : "" );
printf( "%3s", __isascii( ch ) ? "AS" : "" );
printf( "%3s", iscntrl( ch ) ? "C" : "" );
printf( "%3s", __iscsym( ch ) ? "CS " : "" );
printf( "%3s", __iscsymf( ch ) ? "CSF" : "" );
printf( "%3s", isdigit( ch ) ? "D" : "" );
printf( "%3s", isgraph( ch ) ? "G" : "" );
printf( "%3s", islower( ch ) ? "L" : "" );
printf( "%3s", ispunct( ch ) ? "PU" : "" );
printf( "%3s", isspace( ch ) ? "S" : "" );
printf( "%3s", isprint( ch ) ? "PR" : "" );
printf( "%3s", isupper( ch ) ? "U" : "" );
printf( "%3s", isxdigit( ch ) ? "X" : "" );
printf( ".\n" );
}
}
Output
00 AS C .
01 AS C .
02 AS C .
03 AS C .
04 AS C .
05 AS C .
06 AS C .
07 AS C .
08 AS C .
09 AS C S .
0a AS C S .
0b AS C S .
0c AS C S .
0d AS C S .
0e AS C .
0f AS C .
10 AS C .
11 AS C .
12 AS C .
13 AS C .
14 AS C .
15 AS C .
16 AS C .
17 AS C .
18 AS C .
19 AS C .
1a AS C .
1b AS C .
1c AS C .
1d AS C .
1e AS C .
1f AS C .
20 AS S PR .
21 ! AS G PU PR .
22 " AS G PU PR .
23 # AS G PU PR .
24 $ AS G PU PR .
25 % AS G PU PR .
26 & AS G PU PR .
27 ' AS G PU PR .
28 ( AS G PU PR .
29 ) AS G PU PR .
2a * AS G PU PR .
2b + AS G PU PR .
2c , AS G PU PR .
2d - AS G PU PR .
2e . AS G PU PR .
2f / AS G PU PR .
30 0 AN AS CS D G PR X.
31 1 AN AS CS D G PR X.
32 2 AN AS CS D G PR X.
33 3 AN AS CS D G PR X.
34 4 AN AS CS D G PR X.
35 5 AN AS CS D G PR X.
36 6 AN AS CS D G PR X.
37 7 AN AS CS D G PR X.
38 8 AN AS CS D G PR X.
39 9 AN AS CS D G PR X.
3a : AS G PU PR .
3b ; AS G PU PR .
3c < AS G PU PR .
3d = AS G PU PR .
3e > AS G PU PR .
3f ? AS G PU PR .
40 @ AS G PU PR .
41 A AN A AS CS CSF G PR U X.
42 B AN A AS CS CSF G PR U X.
43 C AN A AS CS CSF G PR U X.
44 D AN A AS CS CSF G PR U X.
45 E AN A AS CS CSF G PR U X.
46 F AN A AS CS CSF G PR U X.
47 G AN A AS CS CSF G PR U .
48 H AN A AS CS CSF G PR U .
49 I AN A AS CS CSF G PR U .
4a J AN A AS CS CSF G PR U .
4b K AN A AS CS CSF G PR U .
4c L AN A AS CS CSF G PR U .
4d M AN A AS CS CSF G PR U .
4e N AN A AS CS CSF G PR U .
4f O AN A AS CS CSF G PR U .
50 P AN A AS CS CSF G PR U .
51 Q AN A AS CS CSF G PR U .
52 R AN A AS CS CSF G PR U .
53 S AN A AS CS CSF G PR U .
54 T AN A AS CS CSF G PR U .
55 U AN A AS CS CSF G PR U .
56 V AN A AS CS CSF G PR U .
57 W AN A AS CS CSF G PR U .
58 X AN A AS CS CSF G PR U .
59 Y AN A AS CS CSF G PR U .
5a Z AN A AS CS CSF G PR U .
5b [ AS G PU PR .
5c \ AS G PU PR .
5d ] AS G PU PR .
5e ^ AS G PU PR .
5f _ AS CS CSF G PU PR .
60 ` AS G PU PR .
61 a AN A AS CS CSF G L PR X.
62 b AN A AS CS CSF G L PR X.
63 c AN A AS CS CSF G L PR X.
64 d AN A AS CS CSF G L PR X.
65 e AN A AS CS CSF G L PR X.
66 f AN A AS CS CSF G L PR X.
67 g AN A AS CS CSF G L PR .
68 h AN A AS CS CSF G L PR .
69 i AN A AS CS CSF G L PR .
6a j AN A AS CS CSF G L PR .
6b k AN A AS CS CSF G L PR .
6c l AN A AS CS CSF G L PR .
6d m AN A AS CS CSF G L PR .
6e n AN A AS CS CSF G L PR .
6f o AN A AS CS CSF G L PR .
70 p AN A AS CS CSF G L PR .
71 q AN A AS CS CSF G L PR .
72 r AN A AS CS CSF G L PR .
73 s AN A AS CS CSF G L PR .
74 t AN A AS CS CSF G L PR .
75 u AN A AS CS CSF G L PR .
76 v AN A AS CS CSF G L PR .
77 w AN A AS CS CSF G L PR .
78 x AN A AS CS CSF G L PR .
79 y AN A AS CS CSF G L PR .
7a z AN A AS CS CSF G L PR .
7b { AS G PU PR .
7c | AS G PU PR .
7d } AS G PU PR .
7e ~ AS G PU PR .
7f AS C .