ComfyUI Node

startswith

A True/False Gate That Routes on What a String Begins With

By StableLlama·Created about a year ago·Updated 16 days ago· 51
startswith
    • result
    ◄string►
    ◄prefix►
    ◄start0►
    ◄end0►

    Conditional workflows are where ComfyUI stops being a paint-by-numbers image tool and starts being a real program, and startswith is a genuine gate for them. It answers one binary question - does this string begin with that? - and hands you a BOOLEAN you can feed straight into the pack's if/else or flow-select nodes. Filename prefix, model name, tag start - if you need to branch on it, this is the check.

    How it works

    Straight pass-through to Python's str.startswith(), wrapped in the Basic data handling pack (StableLlama, zero runtime dependencies). Two required inputs: string (what you're testing) and prefix (what you're checking for). Both are plain STRINGs.

    There are two optional INT inputs if you only care about part of the string: start (default 0, where to begin the check) and end (default 0). The end default is the sneaky one - an end of 0 is treated as "to the end of the string," so you can safely ignore it for whole-string checks. Set start to, say, 7 and the node only looks at characters from position 7 onward.

    The output is BOOLEAN - True or False. That's it. It's a pure predicate; it doesn't extract anything.

    The workflow pattern

    This node is half of a pattern, not the whole thing. The classic graph:

    1. Get a filename or identifier as a string (say, from a save path or a model list).
    2. Feed it into startswith with the prefix you care about - "output_", "flux", whatever.
    3. Feed the BOOLEAN into an if/else or flow select node to route the graph down one path or another.

    So "if the checkpoint starts with 'realvis', run the photorealistic post-processing branch, otherwise skip it" becomes a three-node chain instead of manual toggling. The Basic data handling pack is the same one that gives you those flow-control nodes, so everything stays on compatible types.

    Installing it

    Search "Basic data handling" in ComfyUI Manager and restart, or manually:

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

    Restart, done. No dependencies beyond ComfyUI itself.

    Gotchas

    startswith is case-sensitive. "Flux" does not match the prefix "flux" - if you need case-insensitive routing, run the string through lower first and compare against a lowercased prefix. And remember it's an exact-prefix check, so a prefix of "a" matches any string that starts with a, and one of "abcdef" matches nothing in "abc". Short prefixes can match more than you intended; that's usually fine, but worth a glance at your data before you build a routing rule on it.

    CategoryBasic/STRING

    Inputs (4)

    NameTypeDefaultDescription
    stringSTRINGThe text to test.
    prefixSTRINGThe prefix to look for.
    startoptINT0Start position of the checked range.
    endoptINT0End position of the checked range (0 means the end).

    Outputs (1)

    NameTypeDescription
    resultBOOLEANTrue when the text starts with the prefix.