Nodes/ComfyUI-JK-TextTools/String Index Selector
ComfyUI Node

String Index Selector

Pick the Nth item from a delimited string

By Nakamura2828·Created 8 months ago·Updated 8 months ago· 0
String Index Selector
    • selected_item
    • item_count
    textitem1,item2,item3
    delimiter,
    index0
    strip_whitespacetrue
    output_type
    zero_indexedtrue

    String Index Selector is the pack's founding node - the README describes it as the original use case the whole thing was built around. The scenario: some node hands you a comma-separated string like "10,25,42,100" and you want one specific value out of it, typically inside a loop where the loop index tells you which one. This node splits the string, grabs the Nth item, and casts it to a real type so it plugs straight into an INT or FLOAT input.

    The original use case was VHS/frame-extraction style workflows: a video node produces a list of frame numbers as text, and this node picks the frame for the current loop iteration so Save Image writes frame_42.png instead of a constant. It's the difference between "I can only process frame 1" and "I can walk the whole list."

    How it works

    It splits text on delimiter (default ,), strips whitespace from each item, and picks the item at index. Escape sequences are honored, so you can type \n in the delimiter field to split on actual newlines. Then output_type casts the result: STRING, INT, or FLOAT. So:

    text: "10,25,42,100", delimiter: ",", index: 2, output_type: INT
    → 42 as an integer
    

    The zero_indexed toggle (default true) decides whether index 0 is the first item - flip it for 1-based counting. Out-of-range indexes return None plus the item count rather than crashing.

    Inputs and outputs

    • text (STRING) - the delimited string.
    • delimiter (STRING, default ,) - what to split on.
    • index (INT, 0–10000) - which item to take.
    • strip_whitespace (BOOLEAN, default true) - trim each item.
    • output_type (STRING / INT / FLOAT) - the cast to apply.
    • zero_indexed (BOOLEAN, optional, default true).

    Outputs: selected_item (*) and item_count (INT).

    Where it fits

    Loop workflows are the home turf - wire the loop counter into index, get a different value each pass. It also pairs with its own pack: String Splitter parses the whole string into a typed list when you need the items together, List Index Selector does the same job on an already-built list, and String Joiner reverses the process when you need to serialize.

    Installing it

    It's in ComfyUI-JK-TextTools. ComfyUI Manager → search "JK-TextTools" → install, or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/Nakamura2828/ComfyUI-JK-TextTools.git
    

    Restart ComfyUI. No models, no extra pip packages - pure Python string handling.

    Gotchas

    The type cast is the sharp edge: output_type: INT on an item like "cat" raises a ValueError and the node fails loudly. Keep INT/FLOAT for data you're sure is numeric. And remember None comes back silently on out-of-range indexes - if a node downstream starts complaining about a * value, check that your index is actually inside item_count.

    CategoryJK-TextTools/string

    Inputs (6)

    NameTypeDefaultDescription
    textSTRINGitem1,item2,item3
    delimiterSTRING,
    indexINT00–10000
    strip_whitespaceBOOLEANtrue
    output_typeCOMBO3 options: STRING, INT, FLOAT
    zero_indexedoptBOOLEANtrue

    Outputs (2)

    NameTypeDescription
    selected_item*
    item_countINT