Text Trim
Getting the whitespace off the ends
- result
Text Trim is a four-mode whitespace remover: strip from both ends, the left, the right, or - in its all mode - collapse every run of whitespace down to single spaces. It's a small node for a surprisingly common problem, because pasted text is filthy. Copy a tag list from a website and it arrives with stray spaces, trailing newlines, and inconsistent indentation; Text Trim is the quick scrub before that text goes anywhere that cares (a wildcard processor, an LLM prompt, a filename builder).
This is one of the thinner nodes in the pack, so let's be straight about scope: you feed it text, pick a mode, and get a single cleaned result string back. both is str.strip() (default), left is lstrip, right is rstrip. The all mode is the one with teeth - it's ' '.join(text.split()), which collapses any amount of whitespace (spaces, tabs, newlines) anywhere in the string into a single space and trims the ends. "Hello world" → "Hello world", and a multi-line block becomes one line.
Why this node and not Text Trimmer
Full transparency: this pack also ships a node called Text Trimmer (DebugPadawan_TextTrimmer), and they overlap hard. Text Trim's all mode is functionally identical to Text Trimmer's collapse_spaces. The difference is the rest of the roster: Trimmer adds all_whitespace (remove every whitespace character, not just collapse), start/end as aliases for left/right, and a remove_newlines mode. Text Trim's only unique value is the simple, obvious name. If you're starting a new workflow, use Text Trimmer - it's the superset. Reach for this one if it's already in a workflow you inherited, or if you want the four cleanest options and nothing more.
Installation
Both nodes live in the same pack - "DebugPadawan's ComfyUI Essentials" in ComfyUI Manager, or:
cd ComfyUI/custom_nodes
git clone https://github.com/DebugPadawan/DebugPadawans-ComfyUI-Essentials.git
Restart ComfyUI. No models, no dependencies beyond Python stdlib.
Gotchas
The only real surprise is mode all: people expect it to just trim, and it also collapses interior spaces - a deliberately-multiple-spaced string comes out single-spaced. If you only wanted the edges gone, use both. And because ' '.join(text.split()) handles all whitespace, a string that's just a bunch of blank lines collapses to an empty string, which then flows downstream as empty text - usually fine, occasionally confusing. It's a tiny node with no community lore behind it; when the output looks off, the input almost always contains a character you didn't see (tabs, non-breaking spaces, zero-width junk from copied web text). Those aren't stripped by the plain modes - only all removes them.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| text | STRING | — | |
| mode | COMBO | both | 4 options: both, left, right, all |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| result | STRING | — |