6个space字符

-- 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  HThorizontal tab水平制表符
10 \n 空一行 LFline feed换行
11 \x0b十六进制  VTvertical tab垂直制表符
12 \x0c十六进制  FFform feed换页
13 \r  CRcarriage return回车
32 \x20十六进制  space空格

本文链接:https://cs.pynote.net/sf/c/202201301/

-- EOF --

-- MORE --