Nodes/ComfyUI-TextUtils/Join N-Element of String List
ComfyUI Node

Join N-Element of String List

Grab just the first or last N items

By wutipong·Created 3 years ago·Updated about a year ago· 2
Join N-Element of String List
    • TEXT
    texts
    separator/
    n1
    start_from

    Plain Join String List (same pack) glues an entire list together. This one is for when you don't want the whole list - just the first few items, or the last few - joined into a single string. Think "give me the first 3 tags" or "give me the last line of this log," without you having to trim the list yourself somewhere upstream.

    How it works

    It slices the incoming list before joining it. Read straight from the source: if start_from is front (the default), it takes texts[0:n] - the first n items. If you switch it to back, it takes the last n items instead (texts[len(texts)-n : len(texts)]), and if n is bigger than the list, that math is clamped to zero rather than going negative. Either way, the resulting slice gets joined with your separator, same as the plain join node.

    The clamping is worth calling out because it means the node doesn't crash if you get n wrong - ask for more elements than exist and you just get everything, front or back, instead of an error. You don't need to know the exact list length ahead of time.

    Inputs and outputs

    • texts - the list to slice from. Like the plain join node, this is forceInput - it has to come from a wire (Split String to List or similar), you can't type it in.
    • separator - glue between the kept items. Defaults to /.
    • n - how many elements to keep (default 1, range 0–10000). n = 0 gives you an empty string back, not an error.
    • start_from - front or back. front takes the first n items; back takes the last n.
    • Output: TEXT - one joined string.

    How to install it

    Same pack, same process as its siblings:

    • ComfyUI Manager: search "ComfyUI-TextUtils", install, restart.
    • Manual: git clone https://github.com/wutipong/ComfyUI-TextUtils into ComfyUI/custom_nodes, restart.

    No dependencies to install and nothing to download - four self-contained Python files, stdlib only. The repo ships no README, so treat this article (and the node's own tooltips, where present) as the documentation.

    Common issues & troubleshooting

    Nothing happens, output is blank. Check n isn't 0 - that's a valid, silent way to get an empty string, not a bug.

    Wrong end of the list. start_from defaults to front. If you actually wanted the tail of the list - say, the last few lines of something you split earlier - you have to flip it to back explicitly.

    Same forceInput trap as the other join nodes. texts needs a wire, not a typed value - if the input socket looks unusable, that's why. Feed it from Split String to List or another list-producing node.

    Expecting it to reorder or filter, not slice. This node only takes a contiguous chunk from one end - it doesn't let you pick arbitrary indices or filter by content. If you need that, you're looking for something more like Impact Pack's list utilities rather than this pack.

    Categorytext utility

    Inputs (4)

    NameTypeDefaultDescription
    textsSTRING
    separatorSTRING/
    nINT10–10000
    start_fromCOMBO2 options: front, back

    Outputs (1)

    NameTypeDescription
    TEXTSTRING