textutil::trim(n)
π textutil::trim β bestie edition π
okay so you know how you have a string and it's got all this extra whitespace hanging off it like glitter after a craft project? yeah. that's this. it lives in textutil, which is the text and string utilities + macro processing corner of Tcllib, and it's about trimming strings. that's the whole job. and she does it beautifully. β¨
πΈ NAME πΈ
textutil::trim β procedures to trim strings π
β¨ SYNOPSIS β¨
package require Tcl 8.5 9
package require textutil::trim ?0.8?
::textutil::trim::trim string ?regexp?
::textutil::trim::trimleft string ?regexp?
::textutil::trim::trimright string ?regexp?
::textutil::trim::trimPrefix string prefix
::textutil::trim::trimEmptyHeading string
π DESCRIPTION π
so the textutil::trim package hands you a lil set of commands that trim strings, and the slay part is that they trim using arbitrary regular expressions. not just spaces. whatever you want. iconic behavior honestly.
the full roster of procedures is right below, no skips, no cuts. π
::textutil::trim::trim string ?regexp?β takesstring, yeets any leading and trailing substring that matches the regular expressionregexp, and gives you the glow-up back as a new string. and this happens on all the lines in the string, meaning every substring that sits between 2 newline chars, or between the beginning of the string and a newline, or between a newline and the end of the string β or, if the string has no newline at all, then between the beginning and the end of the string.regexpdefaults to"[ \t]+". π§::textutil::trim::trimleft string ?regexp?β same vibe but only the leading side. removes any leading substring instringthat matchesregexpand returns the result as a new string. this applies to any line in the string β any substring between 2 newline chars, or between the beginning of the string and a newline, or between a newline and the end of the string, or, if the string has no newline, between the beginning and the end of the string.regexpdefaults to"[ \t]+". π¦::textutil::trim::trimright string ?regexp?β and this one is the trailing side, the lil cleanup at the end of the sentence. removes any trailing substring instringmatchingregexpand returns the result as a new string. applies to any line in the string β any substring between 2 newline chars, or between the beginning of the string and a newline, or between a newline and the end of the string, or, if the string has no newline, between the beginning and the end of the string.regexpdefaults to"[ \t]+". π::textutil::trim::trimPrefix string prefixβ takes theprefixoff the beginning ofstringand hands you the result. and listen: ifstringdoesn't actually start withprefix, she leaves it completely unchanged. no drama, no error, just vibes. π«Ά::textutil::trim::trimEmptyHeading stringβ hunts down empty lines at the beginning ofstringand removes them. and yes, "empty" includes lines that are only whitespace, we're not fooled by a line full of spaces bestie π. the modified string comes back as the result of the command. π
π BUGS, IDEAS, FEEDBACK π
ngl, this document and the package it describes will undoubtedly contain bugs and other problems. that's just how it is. so please report them in the category textutil of the Tcllib Trackers at http://core.tcl.tk/tcllib/reportlist. and while you're there, also drop any ideas for enhancements you might have for the package and/or the documentation. we love ideas. we eat ideas for breakfast. π
when you're proposing code changes, please send unified diffs, i.e. the output of diff -u. this is not optional, it's the vibe check.
also note: attachments are strongly preferred over inlined patches. to attach something, go to the Edit form of the ticket right after you create it, then use the left-most button in the secondary navigation bar. there you go, you're welcome. π
π SEE ALSO π
regexp(n), split(n), string(n)
π KEYWORDS π
prefix, regular expression, string, trimming
π CATEGORY π
Text processing
okay bye bestie, this was tcllib version 0.8, dated textutil::trim(n), and honestly? she ate. πβ¨ππ¦
π¦ where this page comes from
- fedora 43: tcllib 2.0-3.fc43 Β· TCL
- fedora 44: tcllib 2.0-4.fc44 Β· TCL
- nixos 26.05: tcllib 2.0
- nixpkgs unstable: tcllib 2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms