strsub(3pub)

strsub3pub

Substitute first occurrence of pattern with another string

Usage

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

Overview

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.

Return value

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

Examples

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");

Releases

16 releases since Debian 1.2 (Rex); the text changed 5 times.

  1. 1.2–1.3
  2. 2.0–2.2
  3. 3.0
  4. 3.1–6.0
  5. 7–8
  6. 9–13

Author

Lars Wirzenius ([email protected])

From publib-dev 0.40-4 in Debian 13 (Trixie). Parsed by carta from the page's man source.