Nodes/ComfyUI-JNodes/Trim And Strip
ComfyUI Node

Trim And Strip

Knock the whitespace off the ends of a string

By JaredTherriault·Created 3 years ago·Updated about a month ago· 91
Trim And Strip
    • STRING
    text

    A one-trick node: it removes whitespace from the head and tail of a string. Leading spaces, trailing newlines, that stray tab you didn't notice - gone. The readme describes it in one line ("simply removes whitespace from the head and tail of the given text"), and there's really nothing more to it.

    So why does it exist? Because in ComfyUI you constantly build strings by wiring nodes together - concatenating a base prompt with a style suffix, gluing on a trigger word, assembling text across several nodes. That stitching leaves gaps: a prompt that starts with a blank line, or ends with " , " because two fragments met awkwardly. Feed the result through JNodes_TrimAndStrip and the ends come out clean. It's a small paper-cut fixer, which is exactly the niche the whole JNodes suite lives in.

    How it works

    It's the equivalent of Python's .strip(): it trims whitespace from the beginning and end of the input and returns the rest untouched. Note the "head and tail" scope - it does not touch whitespace in the middle of your text. Internal double-spaces, extra commas between words, and line breaks inside the body all survive. This is purely an end-trim.

    The inputs and outputs

    • text (multiline STRING) - the string to clean up.
    • STRING output - the same text with leading and trailing whitespace removed.

    That's the entire surface. Wire a messy string in, get a tidy one out.

    How to install it

    Via ComfyUI Manager: Install Custom Nodes, search "JNodes", install, restart. Or by hand:

    cd ComfyUI/custom_nodes
    git clone https://github.com/JaredTherriault/ComfyUI-JNodes
    pip install -r ComfyUI-JNodes/requirements.txt
    

    then restart ComfyUI. No model downloads. It's one of the smallest nodes in Jared Therriault's suite.

    Common issues & troubleshooting

    It only trims the ends - for internal cleanup use a different node. This is the thing to get right. If your problem is extra spaces or duplicate commas inside the prompt (a classic result of concatenating fragments), JNodes_TrimAndStrip won't fix it. Reach for JNodes_SplitAndJoin instead - the readme pitches it as "great for removing extraneous spaces and commas from a display prompt," because it splits on a delimiter and rejoins cleanly. Trim-and-strip is for the ends; split-and-join is for the middle.

    Nothing looks different? Your whitespace might be internal. If you ran it and the output looks identical, the whitespace you're worried about probably isn't at the head or tail. Check whether the gap is actually in the middle of the string, where this node deliberately leaves it alone.

    It won't remove commented text or parameters. Cleaning up # comment lines or <params:...> tags is a job for JNodes_RemoveCommentedText and JNodes_RemoveParseableDataForInference respectively. This node treats all of that as ordinary text and only strips surrounding whitespace.

    Genuinely, that's the whole node. It does one tiny thing correctly, and in a graph full of string plumbing that one tiny thing is worth having on hand.

    Categorytext

    Inputs (1)

    NameTypeDefaultDescription
    textSTRING

    Outputs (1)

    NameTypeDescription
    STRINGSTRING