From fb87f58ad96190a258dccff6f2c5faab031010e0 Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Sun, 30 Aug 2020 19:01:02 +0200 Subject: Renamed cstr_destr to cstr_mdestroy(). Added a few more examples. --- examples/replace.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 examples/replace.c (limited to 'examples/replace.c') diff --git a/examples/replace.c b/examples/replace.c new file mode 100644 index 00000000..b31715c1 --- /dev/null +++ b/examples/replace.c @@ -0,0 +1,33 @@ + +#include + +int main () +{ + const char *base = "this is a test string."; + const char *s2 = "n example"; + const char *s3 = "sample phrase"; + const char *s4 = "useful."; + + // replace signatures used in the same order as described above: + + // Ustring positions: 0123456789*123456789*12345 + cstr_t s = cstr_make(base); // "this is a test string." + + cstr_t m = cstr_clone(s); + cstr_append(&m, m.str); + cstr_append(&m, m.str); + printf("%s\n", m.str); + + cstr_replace(&s, 9, 5, s2); // "this is an example string." (1) + printf("(1) %s\n", s.str); + cstr_replace_n(&s, 19, 6, s3+7, 6); // "this is an example phrase." (2) + printf("(2) %s\n", s.str); + cstr_replace(&s, 8, 10, "just a"); // "this is just a phrase." (3) + printf("(3) %s\n", s.str); + cstr_replace_n(&s, 8, 6,"a shorty", 7); // "this is a short phrase." (4) + printf("(4) %s\n", s.str); + cstr_replace(&s, 22, 1, "!!!"); // "this is a short phrase!!!" (5) + printf("(5) %s\n", s.str); + + cstr_mdestroy(&s, &m); +} -- cgit v1.2.3