1Strings(3)                 Library Functions Manual                 Strings(3)
2
3
4

NAME

6       Strings -
7

Detailed Description

9       General string manipulation and utilities functions.
10
11   Functions
12       char * str_base64_encode (char *str)
13           Encodes a given tring to its base64 form.
14       char * str_base64_decode (char *str)
15           Decode a base64 encoded string.
16       char * addnslashes (char *s, int n)
17           Same to addslashes(), except that this one only do the action while
18           'n' is great than 0.
19       char * addslashes (char *s)
20           Add slashes to a string when necessary.
21       char * stripnslashes (char *s, int n)
22           Strip no more than 'n' slashes from a string.
23       char * stripslashes (char *str)
24           Strip slashes from a string.
25       void ltrim (char *str)
26           Strip left white spaces from a string.
27       void rtrim (char *str)
28           Strip right white spaces from a string.
29       void trim (char *str)
30           Strip both left and right white spaces from a string.
31       char * substr (char *src, const int start, const int count)
32           Copy part of a string.
33       char ** explode (char *src, const char *token, int *total)
34           Create an array from a string separated by some special char.
35       char * str_nreplace (char *src, const char *delim, const char *with,
36           int n)
37           Replace characteres in a string, but not more than 'n'.
38       char * str_replace (char *str, const char *delim, const char *with)
39           Replace characteres in a string.
40       int strnpos (char *s, char *ch, unsigned int count)
41           Returns the position of a character in a string, but parses no more
42           that 'n' chars.
43       int strpos (char *s, char *ch)
44           Returns the position of a character in a string.
45       char * strdel (char *s, int start, int count)
46           Delete characters from a string.
47       char * recvline (FILE *s)
48           Reads an entire line.
49       char * make_string (char *s,...)
50           Makes a string.
51

Function Documentation

53   char* addnslashes (char * s, int n)
54       Same to addslashes(), except that this one only do the action while 'n'
55       is great than 0.Parameters:
56           s String to parse
57           n Number of characters to work with.
58
59       See also:
60           addslashes()
61
62            char *name = 'My test string is called ´foobar´';
63            puts(name); // will display My test string is called 'foobar'
64
65            name = addnslashes(name, 31);
66            puts(name); // will display My test string is called ´foobar'
67
68
69
70   char* addslashes (char * s)
71       Add slashes to a string when necessary.Adds a '\' in every quote ( ' ),
72       apostrophe ( ' ) or backslash ( \ ) It's useful when working with
73       databases, for example, because someone can try insert this caracters
74       to try hack the application...
75
76       Parameters:
77           *s String to parse
78
79       Returns:
80           The new string, with slashes
81
82       See also:
83           stripslashes, addnslashes
84
85        char *name = 'My test string is called ´foobar´';
86        puts(name); // will display My test string is called 'foobar'
87
88        name = addslashes(name);
89        puts(name); // will display My test string is called ´foobar´
90
91
92   char** explode (char * src, const char * token, int * total)
93       Create an array from a string separated by some special char.Divides
94       the src string in pieces, each delimited by token and storing the total
95       of pieces in total
96
97       Parameters:
98           src String to parse
99           token Character delimiter to search.
100           total An integer variable passed as reference, which stores the
101           total of itens of the array
102
103       Returns:
104           The array, where each item is one separeted by token
105
106         char **pieces;
107         char *name = 'This,is,a,string,of,test';
108         int total, i;
109         pieces = explode(name, ',', &total);
110         for (i = 0; i < total; i++)
111               printf('Piece %d: %s0, i, *(pieces+i));
112
113
114   void ltrim (char * str)
115       Strip left white spaces from a string.Parameters:
116           str String to parse
117
118       Returns:
119           The new string, without left spaces
120
121       Author:
122           Original code was contribuition by Erik Jansson
123
124       See also:
125           rtrim, trim
126
127        char *s = '     String with spaces    ';
128        printf('_%s_0, s);
129        s = ltrim(s);
130        printf('_%s_0, s);
131
132
133   char* make_string (char * s, ...)
134       Makes a string.Works like printf(), with the difference that it returns
135       a string that is the concatenation of the values passed as parameter.
136
137       Parameters:
138           *s Inicial String and optionally formatation parameters ( just s is
139           allowed )
140
141       Returns:
142           The new String
143
144            char *sql = make_string('INSERT INTO myTable VALUES ('%s', '%s', '%s')', varValue1, varValue2, varValue3);
145
146
147
148       Todo
149           String limits/error checking
150
151   char* recvline (FILE * s)
152       Reads an entire line.Reads a line from the file specified by the file
153       pointer passed as parameter. This function is intead to replace the
154       non-portable GNU getline() function.
155
156       Parameters:
157           s File pointer to the file to read from.
158
159       Returns:
160           String containing the line read or NULL if no more line are
161           available
162
163       Author:
164           Robert Csok
165
166   void rtrim (char * str)
167       Strip right white spaces from a string.Parameters:
168           str String to parse
169
170       Returns:
171           The new string, without left spaces
172
173       Author:
174           Original code was contribuition by Erik Jansson
175
176       See also:
177           ltrim, trim
178
179        char *s = '     String with spaces    ';
180        printf('_%s_0, s);
181        s = rtrim(s);
182        printf('_%s_0, s);
183
184
185   char* str_base64_decode (char * str)
186       Decode a base64 encoded string.Parameters:
187           *str Encoded String to decode
188
189       Returns:
190           The decoded string
191
192       See also:
193           str_base64_encode
194
195   char* str_base64_encode (char * str)
196       Encodes a given tring to its base64 form.Parameters:
197           *str String to convert
198
199       Returns:
200           Base64 encoded String
201
202       See also:
203           str_base64_decode
204
205   char* str_nreplace (char * src, const char * delim, const char * with, int
206       n)
207       Replace characteres in a string, but not more than 'n'.Replace all
208       occourences of *delim on *src with characteres pointed by *with,
209       stopping after 'n' char.
210
211       Parameters:
212           *src String to parse
213           *delim Character to search that will be replaced
214           with String to replace with
215           n Maximum number of chars to parse
216
217       Returns:
218           The new string
219
220       See also:
221           str_replace
222
223         char *linux = 'Linux C';
224         linux = str_nreplace(linux, 'C', 'Cool', strlen(linux));
225         puts(linux);
226        //  -- OR --
227         char *name = 'rAfAel steil';
228         name = str_nreplace(name, 'A', 'a', 3);
229         puts(name);
230
231
232   char* str_replace (char * str, const char * delim, const char * with)
233       Replace characteres in a string.Replace all occourences of *delim on
234       *src with characteres pointed by *with. The problem with the folowing
235       code is that the function only searches for the first caracter of
236       *delim, ingoring the rest. Other problem is speed relacioned: note that
237       the function ever compare the length of *with to do the correct action.
238
239       Parameters:
240           src String to parse
241           delim Character to search that will be replaced
242           with String to replace with
243
244       Returns:
245           The new string
246
247       See also:
248           str_nreplace
249
250         char *linux = 'Linux C';
251         linux = str_replace(linux, 'C', 'Cool');
252         puts(linux);
253        //  -- OR --
254         char *name = 'rAfAel steil';
255         name = str_replace(name, 'A', 'a');
256         puts(name);
257
258
259   char* strdel (char * s, int start, int count)
260       Delete characters from a string.Delete count characters of s, starting
261       in start
262
263       Parameters:
264           s String to search
265           start Initial offset to begin search
266           count Number of characteres to delete
267
268       Returns:
269           The new string
270
271       See also:
272           strndel()
273
274         *txt = 'Some text to test anything';
275         puts(txt);
276         txt = strdel(txt, 2, 8);
277         puts(txt);
278
279
280   char* stripnslashes (char * s, int n)
281       Strip no more than 'n' slashes from a string.Strip the backslash
282       character ( \ ) from a string, stopping after 'n' char
283
284       Parameters:
285           s String to parse
286           n Maximum number of chars to parse
287
288       Returns:
289           The new string, without slashes
290
291       See also:
292           addslashes, stripslashes
293
294        char *name = 'My another string is called \´blablabla\´';
295        puts(name); // will display My another string is called ´blablabla´
296        name = stripslashes(name, 33);
297        puts(name); // will display My another string is called 'blablabla´
298
299
300   char* stripslashes (char * str)
301       Strip slashes from a string.Strip the backslash character ( \ ) from a
302       string
303
304       Parameters:
305           s String to parse
306
307       Returns:
308           The new string, without slashes
309
310       See also:
311           addslashes, stripnslashes
312
313        char *name = 'My another string is called \´blablabla\´';
314        puts(name); // will display My another string is called ´blablabla´
315        name = stripslashes(name);
316        puts(name); // will display My another string is called 'blablabla'
317
318
319   int strnpos (char * s, char * ch, unsigned int count)
320       Returns the position of a character in a string, but parses no more
321       that 'n' chars.Parameters:
322           s String where the search will be done
323           ch Character to search
324           count Maximum number of chars to parse before exiting the function
325
326       See also:
327           strpos()
328
329   int strpos (char * s, char * ch)
330       Returns the position of a character in a string.Parameters:
331           s String where the search will be done
332           ch Character to search
333           count Maximum number of ch to search
334
335       See also:
336           strnpos()
337
338   char* substr (char * src, const int start, const int count)
339       Copy part of a string.Copy count characters from src, starting from
340       start
341
342       Parameters:
343           src String to copy from
344           start Initial offset
345           count Number of chars to copy
346
347       Returns:
348           The new string
349
350        char *part, *str = 'Test one, test two';
351        part = substr(str, 1, 5);
352        puts(part); // -> est o
353
354
355   void trim (char * str)
356       Strip both left and right white spaces from a string.Parameters:
357           str String to parse
358
359       Returns:
360           The new string, without left spaces
361
362       Author:
363           Original code was contribuition by Erik Jansson
364
365       See also:
366           ltrim, trim
367
368        char *s = '     String with spaces    ';
369        printf('_%s_0, s);
370        s = trim(s);
371        printf('_%s_0, s);
372
373
374LibCGI                            13 Mar 2003                       Strings(3)
Impressum