-- TOC --
原来,ASCII中有6个char,用isspace函数判断,都是true!
$ cat is.c
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main(void) {
unsigned int i;
char s[] = {' ','\n','\t','\r','\x0b','\x0c'};
size_t cnt = strlen(s);
printf("%zu\n", cnt);
// check the 6 char
for (i=0; i<cnt; ++i)
if (isspace(s[i])) printf("pos %u is space\n", i);
else printf("pos %u is not space\n", i);
// scan the whole ASCII
cnt = 0;
for (i=0; i<128; ++i)
if (isspace(i)) ++cnt;
printf("There are %zu space characters in ASCII!\n", cnt);
return 0;
}
$ gcc is.c
$ ./a.out
6
pos 0 is space
pos 1 is space
pos 2 is space
pos 3 is space
pos 4 is space
pos 5 is space
There are 6 space characters in ASCII!
Python字符串对象的strip函数,re模块中的\s
,与C语言的6个space char,应该都是保持一致的!
这6个space char分别是:
9 \t 无 HT,horizontal tab,水平制表符
10 \n 空一行 LF,line feed,换行
11 \x0b(十六进制) □ VT,vertical tab,垂直制表符
12 \x0c(十六进制) ↑ FF,form feed,换页
13 \r 无 CR,carriage return,回车
32 \x20(十六进制) 无 space,空格
本文链接:https://cs.pynote.net/sf/c/202201301/
-- EOF --
-- MORE --