Functions | |
char * | str_base64_encode (char *str) |
Encodes a given tring to its base64 form. | |
char * | str_base64_decode (char *str) |
Decode a base64 encoded string. | |
char * | addnslashes (char *s, int n) |
Same to addslashes(), except that this one only do the action while 'n' is great than 0. | |
char * | addslashes (char *s) |
Add slashes to a string when necessary. | |
char * | stripnslashes (char *s, int n) |
Strip no more than 'n' slashes from a string. | |
char * | stripslashes (char *str) |
Strip slashes from a string. | |
void | ltrim (char *str) |
Strip left white spaces from a string. | |
void | rtrim (char *str) |
Strip right white spaces from a string. | |
void | trim (char *str) |
Strip both left and right white spaces from a string. | |
char * | substr (char *src, const int start, const int count) |
Copy part of a string. | |
char ** | explode (char *src, const char *token, int *total) |
Create an array from a string separated by some special char. | |
char * | str_nreplace (char *src, const char *delim, const char *with, int n) |
Replace characteres in a string, but not more than 'n'. | |
char * | str_replace (char *str, const char *delim, const char *with) |
Replace characteres in a string. | |
int | strnpos (char *s, char *ch, unsigned int count) |
Returns the position of a character in a string, but parses no more that 'n' chars. | |
int | strpos (char *s, char *ch) |
Returns the position of a character in a string. | |
char * | strdel (char *s, int start, int count) |
Delete characters from a string. | |
char * | recvline (FILE *s) |
Reads an entire line. | |
char * | make_string (char *s,...) |
Makes a string. |
|
Same to addslashes(), except that this one only do the action while 'n' is great than 0.
|
|
Add slashes to a string when necessary. Adds a '\' in every quote ( " ), apostrophe ( ' ) or backslash ( \ ) It's useful when working with databases, for example, because someone can try insert this caracters to try hack the application...
char *name = "My test string is called \"foobar\""; puts(name); // will display My test string is called "foobar" name = addslashes(name); puts(name); // will display My test string is called \"foobar\" |
|
Create an array from a string separated by some special char. Divides the src string in pieces, each delimited by token and storing the total of pieces in total
char **pieces; char *name = "This,is,a,string,of,test"; int total, i; pieces = explode(name, ",", &total); for (i = 0; i < total; i++) printf("Piece %d: %s\n", i, *(pieces+i)); |
|
Strip left white spaces from a string.
char *s = " String with spaces "; printf("_%s_\n", s); s = ltrim(s); printf("_%s_\n", s); |
|
Makes a string. Works like printf(), with the difference that it returns a string that is the concatenation of the values passed as parameter.
|
|
Reads an entire line. Reads a line from the file specified by the file pointer passed as parameter. This function is intead to replace the non-portable GNU getline() function.
|
|
Strip right white spaces from a string.
char *s = " String with spaces "; printf("_%s_\n", s); s = rtrim(s); printf("_%s_\n", s); |
|
Decode a base64 encoded string.
|
|
Encodes a given tring to its base64 form.
|
|
Replace characteres in a string, but not more than 'n'. Replace all occourences of *delim on *src with characteres pointed by *with, stopping after 'n' char.
char *linux = "Linux C"; linux = str_nreplace(linux, "C", "Cool", strlen(linux)); puts(linux); // -- OR -- char *name = "rAfAel steil"; name = str_nreplace(name, "A", "a", 3); puts(name); |
|
Replace characteres in a string. Replace all occourences of *delim on *src with characteres pointed by *with. The problem with the folowing code is that the function only searches for the first caracter of *delim, ingoring the rest. Other problem is speed relacioned: note that the function ever compare the length of *with to do the correct action.
char *linux = "Linux C"; linux = str_replace(linux, "C", "Cool"); puts(linux); // -- OR -- char *name = "rAfAel steil"; name = str_replace(name, "A", "a"); puts(name); |
|
Delete characters from a string. Delete count characters of s, starting in start
*txt = "Some text to test anything"; puts(txt); txt = strdel(txt, 2, 8); puts(txt); |
|
Strip no more than 'n' slashes from a string. Strip the backslash character ( \ ) from a string, stopping after 'n' char
char *name = "My another string is called \\\"blablabla\\\""; puts(name); // will display My another string is called \"blablabla\" name = stripslashes(name, 33); puts(name); // will display My another string is called "blablabla\" |
|
Strip slashes from a string. Strip the backslash character ( \ ) from a string
char *name = "My another string is called \\\"blablabla\\\""; puts(name); // will display My another string is called \"blablabla\" name = stripslashes(name); puts(name); // will display My another string is called "blablabla" |
|
Returns the position of a character in a string, but parses no more that 'n' chars.
|
|
Returns the position of a character in a string.
|
|
Copy part of a string. Copy count characters from src, starting from start
char *part, *str = "Test one, test two"; part = substr(str, 1, 5); puts(part); // -> est o |
|
Strip both left and right white spaces from a string.
char *s = " String with spaces "; printf("_%s_\n", s); s = trim(s); printf("_%s_\n", s); |