Nodes/Basic data handling/string compare
ComfyUI Node

string compare

The if/else gate for text

By StableLlama·Created about a year ago·Updated 4 days ago· 48
string compare
    • result
    string1
    string2
    operator==
    case_sensitivetrue

    Every interesting workflow has a fork in it. If the prompt mentions this, take that path. If the filename matches, save differently. This node is the gate that makes the decision, and it's the reason people recommend this pack when someone on r/comfyui asks how to do conditional logic in a graph.

    What it does

    string compare takes two strings, applies one of six operators, and returns a boolean. The full operator list is ==, !=, >, <, >=, <=. There's also a case_sensitive toggle, defaulting to on - flip it off and both sides get lowercased before the comparison, so "Berlin" == "berlin" becomes true.

    The inputs that matter:

    • string1, string2 - the two strings being compared (required).
    • operator - dropdown, default == (required).
    • case_sensitive - boolean, default True (required).
    • Output: result, a BOOLEAN.

    That boolean is the whole point. Wire it into the pack's if/else control-flow node (or flow select) and you've got real branching: different prompts, different saves, different paths, all decided by text.

    Where it earns its keep

    The most common real-world use is validating or routing on filenames and prompts. "Is the checkpoint name this one?" before you build a save path. "Does this tag equal that tag?" before you gate a branch. The > and < operators do lexicographic (dictionary-order) comparison, which is handy for sorting strings and occasionally surprising if you expected numbers. Text compare, not math.

    Installing

    Part of Basic data handling by StableLlama. In ComfyUI Manager search "Basic data handling" → Install → restart ComfyUI. Or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/StableLlama/ComfyUI-basic_data_handling
    

    Restart. Zero runtime dependencies - this pack is pure Python stdlib, so it installs cleanly and can't collide with your other nodes' requirements.

    Where people get burned

    The case-insensitive path uses plain .lower(), not casefold(). For most text that's fine; for Unicode edge cases like German ß, it falls short. If you need aggressive folding, run both strings through the pack's casefold node first, then compare with == - that's the accurate route. Also, the result is a boolean that goes downstream like any other boolean: it won't throw or warn if the strings are wildly different types of content, so make sure you're actually comparing what you think you are.

    CategoryBasic/comparison

    Inputs (4)

    NameTypeDefaultDescription
    string1STRING
    string2STRING
    operatorCOMBO==6 options: ==, !=, >, <, >=, <=
    case_sensitiveBOOLEANtrue

    Outputs (1)

    NameTypeDescription
    resultBOOLEAN