STRMTRIM(3pub)

πŸ’… NAME πŸ’…

strmtrim β€” the glow-up function that replaces multiple white spaces with single blanks inside a string ✨

It's giving "squish the extra spaces, keep the vibes". No cap.


πŸŽ€ SYNOPSIS πŸŽ€

#include <publib.h>
char *strmtrim(char *str);

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so bestie, here's the tea πŸ“: strmtrim goes through your string and replaces every run of whitespace characters with a single blank. That's it. That's the whole job. Iconic behaviour, honestly.

The whitespace it cares about is defined by isspace(3) β€” so whatever that says counts as whitespace, that's what gets collapsed. Periodt.

But listen, and this is important πŸ‘‘: it will NOT touch leading and trailing whitespace. It only cleans up the middle. If you want the ends dealt with too, you gotta go grab strltrim(3) and strrtrim(3) for those. Different tools, different jobs, all of them slay. πŸ’…

not me collapsing your internal spaces but leaving your edges exactly how you left them πŸ™ˆ boundary-respecting king behaviour fr fr

✨ RETURN VALUE ✨

strmtrim returns the value of its argument. That's right, it hands you back your own pointer. Same string, same pointer, just tidier in the middle. Lowkey the most chill return value ever. 🫢


πŸ‘€ SEE ALSO πŸ‘€

the whole trim squad, assembled 🌈


🌸 AUTHOR 🌸

Lars Wirzenius β€” lars.wirzenius@helsinki.fi

ty bestie for your service πŸŽ€


okay that's the whole page!! this one lives in the Publib collection, section 3pub of the C Programmer's Manual πŸ’– go forth and collapse those spaces, you've got this, mwah πŸ’‹βœ¨πŸ¦‹

πŸ“¦ where this page comes from