trim text 消除文本前后空格
Kill the stray spaces breaking your prompt
- text
Whitespace is a silent workflow killer. A prompt that arrives with a stray leading space, or a \n where a comma should be, can throw off tag parsing, produce "empty string" surprises in list processing, and make two visually identical prompts hash differently for seed-comparison work. trim_text (2lab) is the one-line fix: it strips leading and trailing whitespace from a string and hands you back the clean version. The subtitle is blunt about it - "eliminate spaces before and after the text."
Where does this actually bite? Mostly at pipeline boundaries. When a string comes from a file, an API response, or a text box where someone hit enter, it frequently drags in invisible characters. If that string then becomes a prompt token, a filename, or an entry in a list, the whitespace becomes a real problem downstream - a batch node matching on exact strings will quietly fail to match. Running strings through this node at the edges makes everything downstream more predictable.
Input and output
text- any string, including ones with sloppy whitespace.- Output:
text- the same string with leading and trailing whitespace removed.
That's the whole node. One input, one output, no settings to get wrong.
How it works
It's Python's string .strip() exposed as a node: remove whitespace characters (spaces, tabs, newlines) from both ends of the string, keep everything in the middle untouched. No regex, no character filtering, no transformations you didn't ask for. It doesn't touch the inside of the string - only the edges.
Installing it
Same install as the rest of comfyUI-tool-2lab. ComfyUI Manager → search "comfyUI-tool-2lab" → install, or:
cd ComfyUI/custom_nodes
git clone https://github.com/AI2lab/comfyUI-tool-2lab
Restart ComfyUI. Pure Python, no models.
Gotchas
- Edge whitespace only. If your problem is double spaces inside the string, this node won't fix it - you need a replace node for that. trim_text is specifically about the ends.
- It's a one-way street. Trimming is destructive in the sense that you can't recover the original from the output. If you need the untouched string later, branch the wire before this node.
- Repo visibility. The pack's GitHub page currently returns 404, likely because the author made it private or renamed it. Fresh clones can fail while existing installs keep working - don't read it as your install error.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| text | STRING | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| text | STRING | — |