Nodes/ComfyCollectorNodes/String List Slicer (CCN)
ComfyUI Node

String List Slicer (CCN)

Pull item #3 out of a comma-separated list, every time

By valkymaera·Created 4 months ago·Updated 10 days ago· 1
String List Slicer (CCN)
    • item
    • list_length
    input_string
    index0
    delimiter,
    strip_whitespacetrue
    default_value

    A list of style presets in a text box. A set of seed values. A line of subjects you want to step through one at a time. ComfyUI has no native way to say "give me the third item in this delimited string," which is exactly the gap String List Slicer (CCN) fills. Give it a string, tell it which index you want, and it hands you that item plus the total count.

    The pairing that makes this node actually useful is with any integer that changes between runs - a primitive int with control_after_generate set to increment, or one of the pack's own counter nodes. Step the index, get the next list item, generate. That turns one text field into a batch queue without touching the graph. It's a small trick, but it's the difference between "edit the prompt every run" and "walk the list."

    How it works

    The node splits input_string on delimiter (default ,), optionally trims each item and drops empties, then returns the item at index. The Python-style touches are where it gets pleasant:

    • Negative indices work. -1 is the last item, -2 second-to-last. Handy when you always want "the last one."
    • Out-of-range returns default_value instead of blowing up. If your list has four items and you ask for index 7, you get an empty string (or whatever you set default_value to) and the real length. The workflow keeps running; you just have to handle the empty.

    strip_whitespace is on by default and does double duty: it trims each item and drops blank entries, which changes list_length. If your list is a, b, , c you'll count 3, not 4. Turn it off if your items genuinely include empties.

    The inputs and outputs that matter

    • input_string - the delimited list (multiline-friendly).
    • index - which item to grab; negatives count from the end.
    • delimiter - the literal split character, default comma.
    • default_value - what you get back when the index is out of range.

    Outputs: item (STRING) and list_length (INT) - the count after any stripping, which is often more useful than the item itself when you're stepping through and need to know when to stop.

    How to install it

    One install for the whole pack. ComfyUI Manager → search ComfyCollectorNodes → Install, or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/valkymaera/ComfyCollectorNodes.git
    

    Then restart ComfyUI. No pip step - the pack adds no Python dependencies. Every node carries a (CCN) suffix in the menu.

    Common issues

    Two things get people. First, the split is literal - a regex metacharacter in your delimiter (like .) will happily match any character, so if your list is separated by something exotic, escape it mentally. Second, remember the index is zero-based. Item 1 in your head is index 0 in the node, and that off-by-one shows up the moment you wire an incrementing int in without checking.

    One more honest note: this node slices strings, not actual ComfyUI lists. If you're working with a real *-list of values from a list-handling pack, you want that pack's index node instead. But for "comma string in, one value out," this is clean and done.

    CategoryCCN/String

    Inputs (5)

    NameTypeDefaultDescription
    input_stringSTRING
    indexINT0-999999–999999
    delimiteroptSTRING,
    strip_whitespaceoptBOOLEANtrue
    default_valueoptSTRING

    Outputs (2)

    NameTypeDescription
    itemSTRING
    list_lengthINT