man strgsub () - substitute all occurences of pattern with another string

NAME

strgsub - substitute all occurences of pattern with another string

SYNOPSIS

#include <publib.h>
int strgsub(char *str, const char *pat, const char *sub, size_t max);

DESCRIPTION

strgsub finds all occurences of the pattern pat in the string str (using a method similar to strstr(3) to find the occurrences, i.e., no regular expressions), and replaces each with sub. If pat does not occur in str, no substitution is made. The size (including the terminating '\0') of the string after the substitutions may be at most max chars. If it would be larger, no substitutions are made.

Of course, if sub is an empty string, the occurences of the pattern are deleted from the string.

RETURN VALUE

strgsub returns the number of substitutions made, or -1 if the result would not have fit into max chars.

EXAMPLE

To substitute every "foo" with "bar" in a line, one might do the following.

strgsub(line, "foo", "bar", strlen(line)+1);

SEE ALSO

AUTHOR

Lars Wirzenius (lars.wirzenius@helsinki.fi)