strip
Trim the Invisible Garbage Off Your Strings
- STRING
The most common invisible bug in text-heavy workflows isn't wrong words - it's whitespace. A trailing newline from a file read, an accidental space after a comma, and suddenly your prompt or filename doesn't match what you typed. strip shaves leading and trailing characters off a string, and nine times out of ten the thing you're removing is whitespace you never saw.
How it works
This is Python's str.strip() in a node, from StableLlama's Basic data handling pack - the zero-dependency collection of plain Python utilities. It returns a copy of the string with leading and trailing characters removed; it doesn't touch anything in the middle.
Two inputs:
string(required) - what you're cleaning.chars(optional, default"") - which characters to strip. Leave it empty and it strips whitespace (spaces, tabs, newlines - all of it). Fill it in and it strips exactly that set of characters from both ends:chars=","removes leading and trailing commas,chars=".,; "removes any of those characters from the edges.
One output, STRING - the cleaned copy.
Why you'd bother
The quiet wins are everywhere once you look:
- Prompt hygiene - clean a prompt pulled from a file or an API before it hits the CLIP encoder.
- Filename cleanup - filenames born from template strings love to accumulate stray spaces or trailing dots, which then break downstream save paths.
- Matching and routing -
stripbefore astartswithor comparison node so invisible characters don't sabotage your logic. This pairing is probably the most common real use.
There are also lstrip and rstrip siblings in the pack if you only want one side trimmed, and removeprefix/removesuffix if you're removing literal strings rather than character sets.
Installing it
Search "Basic data handling" in ComfyUI Manager and restart, or:
cd ComfyUI/custom_nodes
git clone https://github.com/StableLlama/ComfyUI-basic_data_handling
Restart and you're done - the pack has no dependencies and needs no model files.
Gotchas
The chars parameter is a set of characters, not a substring - chars="ab" removes every a and every b from the edges, not the literal string "ab". If you want a literal prefix removed, that's the removeprefix node. Also note that when chars is set, whitespace is not automatically included: chars="," will happily leave a space next to the comma in place. That's the behavior people usually have to rediscover the hard way.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| string | STRING | — | |
| charsopt | STRING | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| STRING | STRING | — |