Nodes/ComfyUI-string-util/String StartsWith
ComfyUI Node

String StartsWith

A cheap prefix check for your conditional branches

By kale4eat·Created 2 years ago·Updated 2 years ago· 7
String StartsWith
    • bool
    s
    prefix

    String StartsWith answers one question: "does this text begin with that?" It's a boolean, it's exact, and it's the kind of cheap predicate that makes a node graph feel programmable. If you've ever wanted your workflow to make a decision based on what a string starts with, this is the node that hands you the switch.

    What it is

    It runs Python's s.startswith(prefix) and returns the result as a BOOLEAN. If s begins with prefix, you get True; otherwise False. Nothing clever, no fuzzy matching - either the opening characters match exactly, or they don't.

    Where it pays for itself: routing on filenames and identifiers. Checking whether a filename begins with "test_" so you can route it to a different output path. Checking whether a mode string starts with "video" to switch samplers. Anything where the beginning of the text is meaningful. Feed the boolean into a boolean switch, reroute, or conditional node and the graph branches itself.

    The inputs and outputs

    • s (STRING) - the text being tested.
    • prefix (STRING) - the substring you want at the start.
    • bool (BOOLEAN) - True if s starts with prefix.

    Note the empty case: an empty prefix matches everything ("anything".startswith("") is True in Python), so an unset prefix will return True for any non-empty input. That's a quiet surprise if you leave the field blank.

    How to install it

    Part of the string-util pack, a single dependency-free repo:

    cd ComfyUI/custom_nodes
    git clone https://github.com/kale4eat/ComfyUI-string-util
    

    or install "ComfyUI-string-util" from ComfyUI Manager and restart. It sits under the string-util category.

    Common issues

    Two things to keep straight. The comparison is case-sensitive: "Test" does not start with "test". Normalize both sides with String Upper or String Lower (same pack) if you want case-insensitive checks. And it's the start only - if you need to test the end of a string, that's String EndsWith, also in this pack. Checking "is the substring anywhere at all" is String Find. Pick the right predicate and your conditional logic stays readable.

    Categorystring-util

    Inputs (2)

    NameTypeDefaultDescription
    sSTRING
    prefixSTRING

    Outputs (1)

    NameTypeDescription
    boolBOOLEAN