summaryrefslogtreecommitdiffhomepage
path: root/misc/examples/splitstr.c
blob: a3c12a3a3d3dda17e0eb76b37f25348bafd4da8d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <stdio.h>
#define i_extern // cstr + utf8 functions
#include <stc/cregex.h>
#include <stc/csview.h>

int main()
{
    puts("Split with c_fortoken (csview):");

    c_fortoken (i, "Hello World C99!", " ")
        printf("'%.*s'\n", c_ARGSV(i.token));


    puts("\nSplit with c_formatch (regex):");

    c_with (cregex re = cregex_from("[^ ]+", CREG_DEFAULT), cregex_drop(&re))
        c_formatch (i, &re, "  Hello   World      C99! ")
            printf("'%.*s'\n", c_ARGSV(i.match[0]));
}