Nodes/comfyui-fb-utils/FB String Strip
ComfyUI Node

FB String Strip

Kill the stray spaces and brackets before they bite you

By FredBill1·Created 2 years ago·Updated about a year ago· 3
FB String Strip
    • STRING
    value
    chars
    chars_as_raw_strfalse
    lefttrue
    righttrue

    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/trailing a, b, or c - 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 of a and b from 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 left and right off, 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.

    CategoryFredBill1

    Inputs (5)

    NameTypeDefaultDescription
    valueSTRING
    charsSTRING
    chars_as_raw_strBOOLEANfalse
    leftBOOLEANtrue
    rightBOOLEANtrue

    Outputs (1)

    NameTypeDescription
    STRINGSTRING