Nodes/comfyui-psd2png/StringInsert
ComfyUI Node

StringInsert

StringInsert

By violet-chen·Created 3 years ago·Updated about a year ago· 21
StringInsert
    • STRING
    stringa,b,c
    find_string,
    index0
    insert_stringthis is insert string

    StringInsert does one thing, in about eight lines of Python: it splits a string on a delimiter, pushes another string into the middle of the resulting list, and joins everything back together. That's the whole node. It's bundled in the comfyui-psd2png pack, which is mostly about reading layered Photoshop files - so yes, it's the odd one out, the utility that tagged along because the author needed it while building something else.

    You'd reach for it when you're assembling comma-separated prompt or tag lists on the fly and want a token inserted at a specific position without retyping the string. Typical use: you have a base prompt string coming out of another node, and you want to wedge a style keyword or a quality tag in the middle of the list every run - the kind of thing that's fiddly to do by hand and pointless to hardcode.

    How it works

    string_list = string.split(find_string)
    string_list.insert(index, insert_string)
    result = find_string.join(string_list)
    

    That's it, and the test.py in the repo shows it running against a 26-letter comma list. Split on the delimiter, insert, rejoin with the same delimiter. The node also prints the result into its own body, so you can see exactly what came out without wiring up a text preview.

    The inputs

    • string - the text you're operating on, e.g. "a,b,c".
    • find_string - the delimiter to split and rejoin on. Comma by default.
    • index - where in the split list, not where in the string. This is the trap. With "a,b,c" and a comma delimiter, index 1 doesn't mean "after the first character," it means "between a and b."
    • insert_string - what gets pushed in.

    The single STRING output feeds straight into a CLIP Text Encode, a prompt-formatting node, or any other string input.

    The gotcha to remember

    index counts positions in the split list. Inserting at 0 prepends; inserting at a number bigger than the list length appends to the end - no error, thanks to Python's forgiving list.insert. And if the delimiter never appears in your string, the whole thing is one element, so index 0 gives you "insert_string, your_original_string". If that's not what you meant, check your delimiter.

    Install

    Same as its packmate: ComfyUI Manager, search "comfyui-psd2png", or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/violet-chen/comfyui-psd2png
    

    then restart ComfyUI. The pack's only dependency is psd-tools for the PSD node, so nothing extra to install for this one - it's pure stdlib.

    Honest verdict: this is more of a code snippet than a node. If you already run this pack, it's free and does the job. If you'd otherwise install a whole extra pack for it - don't; ComfyUI's built-in text concatenation plus a little list wrangling gets you the same place with more visible steps. But for the one workflow where you need a tag inserted mid-list every run, it's genuinely the fastest thing available.

    Categoryutils

    Inputs (4)

    NameTypeDefaultDescription
    stringSTRINGa,b,c
    find_stringSTRING,
    indexINT00–999
    insert_stringSTRINGthis is insert string

    Outputs (1)

    NameTypeDescription
    STRINGSTRING