summaryrefslogtreecommitdiffhomepage
path: root/misc/examples/strings/splitstr.c
diff options
context:
space:
mode:
Diffstat (limited to 'misc/examples/strings/splitstr.c')
-rw-r--r--misc/examples/strings/splitstr.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/misc/examples/strings/splitstr.c b/misc/examples/strings/splitstr.c
new file mode 100644
index 00000000..ef7ed174
--- /dev/null
+++ b/misc/examples/strings/splitstr.c
@@ -0,0 +1,21 @@
+#include <stdio.h>
+#define i_import // cstr + utf8 functions
+#include <stc/cregex.h>
+#define i_implement
+#include <stc/csview.h>
+
+int main(void)
+{
+ puts("Split with c_fortoken (csview):");
+
+ c_fortoken (i, "Hello World C99!", " ")
+ printf("'%.*s'\n", c_SV(i.token));
+
+ puts("\nSplit with c_formatch (regex):");
+
+ cregex re = cregex_from("[^ ]+");
+ c_formatch (i, &re, " Hello World C99! ")
+ printf("'%.*s'\n", c_SV(i.match[0]));
+
+ cregex_drop(&re);
+}