STRSUB(3pub)
β¨ NAME β¨
okay so bestie, meet strsub β it substitutes the first occurrence of a pattern with another string π
πΈ SYNOPSIS πΈ
#include <publib.h>
char *strsub(char *str, const char *pat, const char *sub);
π¦ DESCRIPTION π¦
So here's the tea β: strsub goes looking for the first time the pattern pat shows up inside the string str, and it does that using a method similar to strstr(3) β which is a fancy way of saying no regular expressions, bestie, it's just plain matching π β and then it swaps that match out for sub.
And if pat literally never shows up in str? Then nothing happens. No substitution, no drama, we move on π.
Oh and of course, if sub is an empty string, the pattern just gets deleted from the string. Poof. Gone. It's giving vanishing act β¨.
π RETURN VALUE π
strsub hands you back a pointer to the first character after the substitution π«Ά β or NULL if no substitution was made, because sometimes the answer is just no π.
π EXAMPLE π
Say you wanna substitute up to two occurrences of "foo" with "bar" in a line. Iconic behaviour, honestly. You'd do:
p = strsub(line, "foo", "bar");
if (p != NULL)
strsub(line, "foo", "bar");
See the move? First call does the swap, and if it actually worked (p != NULL) you go again for round two π.
π SEE ALSO π
β AUTHOR β
Lars Wirzenius (lars.wirzenius@helsinki.fi) β the main character who wrote this π«‘
okay that's the whole page bestie, no cap π this lil gem lives in the Publib C Programmer's Manual, page STRSUB(3pub), so go forth and substitute responsibly πΈβ¨
π¦ where this page comes from
- debian bookworm: publib-dev 0.40-3+b1 Β· BSD-2-Clause
- debian trixie: publib-dev 0.40-4 Β· BSD-2-Clause
- ubuntu jammy: publib-dev 0.40-3build1 Β· BSD-2-Clause
- ubuntu noble: publib-dev 0.40-3build1 Β· BSD-2-Clause
- ubuntu questing: publib-dev 0.40-4
- ubuntu resolute: publib-dev 0.40-4build1 Β· BSD-2-Clause
- ubuntu stonking: publib-dev 0.40-4build1 Β· BSD-2-Clause
- Copyright (c) 1994-2006 Lars Wirzenius. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms