FB String Strip
Kill the stray spaces and brackets before they bite you
- STRING
Stray whitespace is the silent killer of clean prompts and filenames. A trailing space sneaks into a tag, a bracket stays glued to a word after a split, and suddenly your output has masterpiece with a phantom space or a filename with [ welded to it. FB String Strip trims characters off the ends of a string - and that's basically the entire job, done in one small node instead of a regex detour.
How it works
Under the hood it's Python's strip(), lstrip(), and rstrip() depending on which sides you ask for. Two behaviors define everything else:
- chars is a set of characters, not a substring. This is the classic gotcha. Put
"abc"in the field and the node strips any leading/trailinga,b, orc- it does not look for the literal string"abc". If you wanted to strip the exact word, this is the wrong tool; it's built for removing individual characters like spaces, quotes, or brackets. - Empty chars strips whitespace. Leave the field blank (the default) and it trims spaces, tabs, and newlines from the ends - the behavior 90% of people actually want.
The chars_as_raw_str flag is the same unicode-escape story as the pack's Split and Join nodes: off (default) means \t in the chars field becomes a real tab; on means it's literal.
Inputs and outputs
- value - the string to trim (force-input, so wire it in from another node).
- chars - which characters to strip; blank means whitespace.
- chars_as_raw_str - whether to interpret escape sequences in chars.
- left - strip from the left end (default on).
- right - strip from the right end (default on).
- STRING - the trimmed output.
Where it fits
The most natural spot is right after a split or list operation. FB String Split and FB String Join preserve spaces exactly, so a CSV split on , leaves you with " prompt" items. Drop an FB String Strip in the path and the items come out clean before they reach the sampler or a filename builder.
It's also handy for stripping quote or bracket characters off a filename, or cleaning a single prompt line before it hits your text encoder - both sides on by default, and the left/right toggles let you strip only one end when that's what the data needs.
Gotchas
- It's characters, not words.
"ab"strips any mix ofaandbfrom the ends. If your result comes out looking over-trimmed, this is why. - Only the ends.
" hello "becomes"hello", but"he llo"keeps its middle space - no substring removal in here. - With both
leftandrightoff, the string passes through untouched. Harmless, but a sign you probably don't need this node in that spot.
Install
Same story as the rest of the pack - no dependencies, no models:
cd ComfyUI/custom_nodes
git clone https://github.com/FredBill1/comfyui-fb-utils
Restart ComfyUI and look under the FredBill1 category (ComfyUI Manager: search comfyui-fb-utils). The entire pack is Python standard library - no requirements.txt, no pip step, nothing that can clash with your other nodes. The README is one line, but the strip logic is a handful of readable lines in the source if you want to verify the character-set behavior before you trust it.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| value | STRING | — | |
| chars | STRING | — | |
| chars_as_raw_str | BOOLEAN | false | — |
| left | BOOLEAN | true | — |
| right | BOOLEAN | true | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| STRING | STRING | — |