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

strsub - substitute first occurrence of pattern with another string

Author

       Lars Wirzenius (lars.wirzenius@helsinki.fi)

Publib                                        C Programmer's Manual                                 STRSUB(3pub)

Description

strsub  finds  the  first  occurrence  of  the  pattern  pat in the string str (using a method similar to
       strstr(3), i.e., no regular expressions), and replaces it with sub.  If pat does not  occur  in  str,  no
       substitution is made.

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

Example

       To substitute up to two occurrences of "foo" with "bar" in a line, one might do the following.

            p = strsub(line, "foo", "bar");
            if (p != NULL)
                 strsub(line, "foo", "bar");

Name

       strsub - substitute first occurrence of pattern with another string

Return Value

strsub  returns  a  pointer to the first character after the substitution, or NULL if no substitution was
       made.

See Also

publib(3), strstr(3), strgsub(3)

Synopsis

       #include <publib.h>
       char *strsub(char *str, const char *pat, const char *sub);