STRZAP(3pub)

✨ STRZAP(3pub) ✨

okay so bestie, welcome to the strzap page from the C Programmer's Manual πŸ’– this one's a lil function from publib and she is tiny but she is mighty, fr fr.


🌸 NAME 🌸

strzap β€” remove pattern from beginning of string, if it is there πŸŽ€

like. if the pattern is there, she zaps it. if it's not there, she does nothing. no drama, no notes. πŸ’…


πŸ¦‹ SYNOPSIS πŸ¦‹

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

that's it. that's the whole vibe. one header, one function, two args. iconic. ✨


πŸ’œ DESCRIPTION πŸ’œ

so here's the tea β˜• strzap compares the beginning of str with all of pat, and if they are the same, it removes the beginning from str.

the way that it literally just looks at the front of your string and checks "hey, is this the pattern?" β€” and if yes? gone. removed. no cap. the beginning of str gets yeeted and what's left is what comes after the pattern. 🫢

if they're not the same, she simply does not touch anything. main character energy: unbothered, moisturized, in her lane. 🌈


πŸ”₯ RETURN VALUE πŸ”₯

  • strzap returns non-zero if it removed anything
  • returns 0 if not

so like, check the return value if you wanna know whether the zap actually happened. it's giving "receipts". 🧚


πŸ‘‘ SEE ALSO πŸ‘‘

(yes bestie, there's a sibling function that zaps from the end. go look at strendzap(3) if that's your thing. iykyk 😭)


πŸ’– AUTHOR πŸ’–

Lars Wirzenius (lars.wirzenius@helsinki.fi) β€” thank you for this lil gem, king πŸ‘‘


⚠️ reminder bestie: strzap modifies str in place when it zaps, so don't be passing in anything you can't/shouldn't change. the manpage doesn't say more than that, so i'm not gonna make stuff up. periodt. πŸ’€

and that's the whole page, fr fr πŸ’œ this was Publib, from the C Programmer's Manual β€” STRZAP(3pub), mwah, slay, go zap some strings bestie πŸ’…βœ¨πŸŽ€

πŸ“¦ where this page comes from