logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

strgsub - substitute all occurrences of pattern with another string

Author

       Lars Wirzenius (lars.wirzenius@helsinki.fi)

Publib                                        C Programmer's Manual                                STRGSUB(3pub)

Description

strgsub  finds  all occurrences 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 occurrences of the pattern are deleted from the string.

Example

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

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

Name

       strgsub - substitute all occurrences of pattern with another string

Return Value

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

See Also

publib(3), strstr(3), strsub(3)

Synopsis

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

See Also