ComfyUI Node

String Find

Searching inside a string — and one output that lies to you

By kale4eat·Created 2 years ago·Updated 2 years ago· 7
String Find
    • index
    • found
    s
    value

    String Find is how you ask "is this substring in there, and where?" - the kind of check that unlocks conditional logic in a ComfyUI graph. It's genuinely useful, and it has a bug in its boolean output that you need to know about before you trust it. Let me show you, because it's the kind of thing that eats an hour of debugging.

    What it does

    Feed it a string s and a value to look for, and it runs Python's s.find(value). You get two outputs:

    • index (INT) - the 0-based position of the first occurrence of value, or -1 if it isn't there.
    • found (BOOLEAN) - whether the search succeeded.

    Here's the lie: found is computed as index > 0, not index >= 0. That means if value appears at position 0 - i.e., the string starts with what you searched for - the node reports found = False even though the search clearly succeeded. Searching for "cat" in "catastrophe" returns index 0 and found False. That is a real bug in this pack, and it will silently flip your conditional branch for the most common case there is.

    How to use it anyway

    The index output is honest, so that's your source of truth. index != -1 means found; index == -1 means not. If your downstream logic uses found, either accept the edge case or build the condition on index instead.

    Where this shines: routing. Say you're checking whether a prompt contains a style tag so you can reroute to a different sampler or upscaler. Compare the index against -1, feed the result into a boolean switch or reroute node, and the graph decides for itself.

    The inputs and outputs

    • s (STRING) - the text to search.
    • value (STRING) - the substring to look for.
    • index (INT) - first occurrence position, -1 if absent.
    • found (BOOLEAN) - buggy at index 0, as described.

    How to install it

    No dependencies, no model files - just the repo:

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

    Or install "ComfyUI-string-util" via ComfyUI Manager and restart. It lands under the string-util category.

    Common issues

    Beyond the found bug, two small things. Searching for an empty value returns index 0 (Python's behavior), so found reports False - again the bug. And find only catches the first occurrence; if you need to know how many times something appears, use String Count in the same pack.

    Categorystring-util

    Inputs (2)

    NameTypeDefaultDescription
    sSTRING
    valueSTRING

    Outputs (2)

    NameTypeDescription
    indexINT
    foundBOOLEAN