ComfyUI Node

Trim Text _O

The whitespace cleanup nobody wants to do by hand

By omar92·Created 3 years ago·Updated 5 months ago· 181
Trim Text _O
    • STRING
    text

    Annoying things hide at the edges of strings: a leading space that breaks a tag, a trailing newline that a file read or an AI response left behind, indentation that snuck in from a multiline field. Trim Text _O is the two-second fix - it strips leading and trailing whitespace from a string and hands you the clean version.

    It's in the Quality of Life Suit under O/text/operations, and it earns its place through the pack's own OpenAI nodes. ChatGPT output frequently comes back wrapped in newlines or with stray spaces, and a string with hidden whitespace can quietly break a downstream exact-match operation - Replace Text _O won't find "masterpiece" if the string starts with "\nmasterpiece", and a QOL Split String with a ", " delimiter will leave stray spaces in your pieces. Running a trim between an LLM node and your string operations saves you the kind of debugging session that makes people quit ComfyUI for the evening.

    How it works

    The whole mechanism is Python's str.strip(), which removes whitespace from both ends - spaces, tabs, newlines, carriage returns. It does not touch whitespace inside the string, so "a, b" stays "a, b"; only the ends get cleaned. The single input is text (a plain single-line widget), and the single output is the trimmed STRING.

    There's nothing else to configure, which is the point. Drop it in the string pipeline, connect input to output, and move on with your life.

    Installing

    Pack-wide, same as all Quality of Life Suite nodes:

    cd ComfyUI/custom_nodes
    git clone https://github.com/omar92/ComfyUI-QualityOfLifeSuit_Omar92.git
    

    or search ComfyUI-QualityOfLifeSuit_Omar92 in ComfyUI Manager, then restart ComfyUI (a browser refresh isn't enough). No dependencies.

    The honest take

    This is a genuinely thin node - one input, one output, one line of logic. It's not going to impress anyone, and it won't pad out a portfolio. But it's exactly the kind of boring utility that keeps a pipeline honest: AI-generated prompts are full of invisible whitespace, and having a dedicated trim step makes your workflow robust to it instead of fragile. When a string comparison mysteriously fails and you discover the culprit was a trailing \n, you'll be glad this node is one right-click away.

    CategoryO/text/operations

    Inputs (1)

    NameTypeDefaultDescription
    textSTRING

    Outputs (1)

    NameTypeDescription
    STRINGSTRING