Nodes/comfyui-lopi999-nodes/Concatenate With Prefix
ComfyUI Node

Concatenate With Prefix

Join strings with a prefix AND a counter, not just a delimiter

By LaVie024·Created about a year ago·Updated 8 months ago· 8
Concatenate With Prefix
    • STRING
    delimiter,
    prefix%n%:
    string_1
    string_2
    string_3
    string_4
    string_5
    string_6
    string_7
    string_8

    Every string concatenation node lets you pick a delimiter. This one adds the thing most of them forget: a prefix that gets applied to every piece, with a built-in %n% counter so each segment can be numbered. The author's framing is fair - "most concatenation nodes only let you specify a delimiter. Why not a prefix as well?" - and the dynamic counter is the part you didn't know you wanted until you're building a labeled prompt block.

    Why you'd reach for it

    The killer use case is metadata and sectioned prompts. Instead of getting "artist_a, artist_b, artist_c" you get "1: artist_a, 2: artist_b, 3: artist_c" - a numbered, prefixed block that reads like a real list. It also shines when you're assembling a prompt from multiple sources and want a consistent label on each piece, like "style: watercolor" repeated per segment. If you've ever wanted to slap a category onto every chunk of a concatenated string without doing it by hand, this is the node.

    How it works

    It takes up to eight optional string_N inputs, drops the empty ones, and joins the survivors in order with your delimiter. The prefix is applied to each segment before joining, and any %n% inside the prefix is replaced with the segment's position (1-based). So with prefix "%n%: " and delimiter ", ", two strings become "1: first, 2: second". Because the prefix is a normal string field, you can also leave out %n% entirely and just use it as a constant label - the counter is an option, not a requirement.

    The inputs that matter

    • delimiter (STRING, default ", ") - what goes between segments.
    • prefix (STRING, default "%n%: ") - what leads each segment; %n% becomes the counter.
    • string_1 through string_8 (STRING, all optional) - the pieces to join. Empty inputs are skipped, so you can wire all eight and leave some unused.
    • STRING - the joined result.

    Installing it

    It ships in comfyui-lopi999-nodes:

    cd ComfyUI/custom_nodes
    git clone https://github.com/LaVie024/comfyui-lopi999-nodes
    

    Restart ComfyUI, or use ComfyUI Manager and search "comfyui-lopi999-nodes." No models, no dependencies.

    Common issues

    The ordering is by input number, not by wiring order - string_2 always follows string_1 regardless of where you dragged the wires, which is what you want but worth knowing when a graph looks tangled. The counter is 1-based, so the first segment is 1, and only segments that survive the empty-filter get numbered; a missing string_2 means string_3 becomes 2. And the %n% replacement only works in the prefix field - the delimiter is left literally alone.

    Categorylopi999/string

    Inputs (10)

    NameTypeDefaultDescription
    delimiterSTRING,
    prefixSTRING%n%:
    string_1optSTRING
    string_2optSTRING
    string_3optSTRING
    string_4optSTRING
    string_5optSTRING
    string_6optSTRING
    string_7optSTRING
    string_8optSTRING

    Outputs (1)

    NameTypeDescription
    STRINGSTRING