strings.c
Go to the documentation of this file.
1 
10 #include <GKlib.h>
11 
12 
13 /*************************************************************************/
15 /*************************************************************************/
17 {
18  char *new_str;
19  int rc;
20 
21  rc = gk_strstr_replace("This is a simple string", "s", "S", "", &new_str);
22  printf("%d, %s.\n", rc, new_str);
23  gk_free((void **)&new_str, LTERM);
24 
25 
26  rc = gk_strstr_replace("This is a simple string", "s", "S", "g", &new_str);
27  printf("%d, %s.\n", rc, new_str);
28  gk_free((void **)&new_str, LTERM);
29 
30 
31  rc = gk_strstr_replace("This is a simple SS & ss string", "s", "T", "g", &new_str);
32  printf("%d, %s.\n", rc, new_str);
33  gk_free((void **)&new_str, LTERM);
34 
35 
36  rc = gk_strstr_replace("This is a simple SS & ss string", "s", "T", "ig", &new_str);
37  printf("%d, %s.\n", rc, new_str);
38  gk_free((void **)&new_str, LTERM);
39 
40  rc = gk_strstr_replace("This is a simple SS & ss string", "\\b\\w(\\w+)\\w\\b", "$1", "ig", &new_str);
41  printf("%d, %s.\n", rc, new_str);
42  gk_free((void **)&new_str, LTERM);
43 
44  rc = gk_strstr_replace("This is a simple SS & ss string", "\\b\\w+\\b", "word", "ig", &new_str);
45  printf("%d, %s.\n", rc, new_str);
46  gk_free((void **)&new_str, LTERM);
47 
48  rc = gk_strstr_replace("http://www.cs.umn.edu/This-is-something-T12323?pp=20&page=4",
49  "(http://www\\.cs\\.umn\\.edu/)(.*)-T(\\d+)", "$1$2-P$3", "g", &new_str);
50  printf("%d, %s.\n", rc, new_str);
51  gk_free((void **)&new_str, LTERM);
52 
53  rc = gk_strstr_replace("http://www.cs.umn.edu/This-is-something-T12323?pp=20&page=4",
54  "(\\d+)", "number:$1", "ig", &new_str);
55  printf("%d, %s.\n", rc, new_str);
56  gk_free((void **)&new_str, LTERM);
57 
58 
59  rc = gk_strstr_replace("http://www.cs.umn.edu/This-is-something-T12323?pp=20&page=4",
60  "(http://www\\.cs\\.umn\\.edu/)", "[$1]", "g", &new_str);
61  printf("%d, %s.\n", rc, new_str);
62  gk_free((void **)&new_str, LTERM);
63 
64 
65 
66 }
67 
68 
69 
70 int main()
71 {
73 
74 /*
75  {
76  int i;
77  for (i=0; i<1000; i++)
78  printf("%d\n", RandomInRange(3));
79  }
80 */
81 }
82 
main
int main()
Definition: strings.c:70
gk_free
void gk_free(void **ptr1,...)
Definition: memory.c:202
test_strstr_replace
void test_strstr_replace()
Definition: strings.c:16
gk_strstr_replace
int gk_strstr_replace(char *str, char *pattern, char *replacement, char *options, char **new_str)
Regex-based search-and-replace function.
Definition: string.c:94
LTERM
#define LTERM
Definition: gk_defs.h:14
GKlib.h


gtsam
Author(s):
autogenerated on Fri Nov 1 2024 03:36:27