Nodes/ComfyUI CoolB Nodes/CB String Selector ⚡️
ComfyUI Node

CB String Selector ⚡️

One prompt list, a different line on every run

By CoolBreeze164·Created 29 days ago·Updated 21 days ago· 2
CB String Selector ⚡️
    • STRING
    ◄text►
    ◄delimiternewline►
    ◄index0►

    What you reach for it for

    Prompt variety without opening a hundred CLIP Text Encode nodes. You write a list of prompts - one per line, or comma-separated, or space-separated - and this node hands back exactly one of them. Change the number, get a different one.

    That's it. Which is the point: the packing is the whole node. ComfyUI's dynamic-prompt syntax ({this|that|the other}) does a similar job inline inside the prompt, but it picks at random with no control over which combination you got. This is the deterministic version - the list lives in a text box you can read, and an integer decides what comes out, which is exactly what you want when the "same graph, different prompt" pipeline gets handed to a script or an API.

    The other half of the use case is splitting things that aren't prompts. A list of style names, a list of LoRA trigger words, a list of filenames, a line of settings you parsed out of a config - split a delimited string and index into it.

    How it works

    Three inputs, no magic:

    • text - the multiline box holding your list.
    • delimiter - newline, comma or space. Maps to "\n", "," and " ".
    • index - an INT, 0 to 10000, default 0.

    It splits text on the chosen separator. If you picked comma or space it strips whitespace from each piece, so a, b, c gives you three clean items rather than two items with a leading space. Then it drops anything empty - handy when a trailing newline or a double comma sneaks in, mildly annoying because it means a deliberate blank line shifts every index below it.

    The last step is the one worth knowing: index % len(parts). The index wraps modulo the list length instead of erroring. Ask for item 7 in a three-item list and you get item 1, no complaint. Negative indices wrap too, since Python's modulo never returns a negative for a positive divisor.

    With newline as the delimiter, note that items are not stripped - only the comma and space paths call .strip(). A trailing space on a line travels into your prompt with it. ComfyUI's tokenizer won't care, but if you're comparing that string later with CB String List Match Index, it absolutely will.

    Inputs and outputs

    text, delimiter and index are all you set. The single output is unnamed and typed STRING - wire it wherever a string goes, usually a CLIP Text Encode.

    The useful trick: right-click the index widget and choose Convert widget to input. Now you can drive it. Feed it an INT with control_after_generate set to increment and every queue hands you the next line in your list. Feed it from a seed node for a reproducible shuffle, or from a keyword matcher downstream when you want the prompt chosen by content rather than by count.

    One cross-node gotcha to keep in mind: index here is 0-based, so index 0 is the first line. If you're feeding it from CB String List Match Index, that node returns a 1-based index. Wire them together naively and you will consistently get the line after the one you matched. Subtract one, or pad your list with a dummy first entry.

    Installing it

    Manager → Custom Nodes Manager → search ComfyUI CoolB Nodes → Install → restart. Manual:

    cd ComfyUI/custom_nodes
    git clone https://github.com/CoolBreeze164/ComfyUI-CoolB-Nodes
    

    No models, no extra Python packages - the pack's audio imports are all optional and this node touches none of them anyway.

    Common issues

    The output isn't what line N says. Count blank lines and non-printables. Empty entries are filtered out before indexing, so the item you think is number four can be number three, and trailing whitespace can make two "identical" lines non-identical.

    Nothing comes out at all. With an empty text box the split produces nothing and the node returns an empty string rather than an error. That's also what happens when your delimiter doesn't appear anywhere - a comma-delimited list with no commas is one item, and any index wraps back onto it.

    It seems to keep returning the same line. This node is not an output node, so it runs when something downstream needs it. If the graph isn't re-running - which happens on 2026 models where almost everything is cached and only the sampler's inputs move - the index never changes. Check you're actually driving the index from something that updates.

    Indexing beyond the list is silent. No warning, no red node, just a wrapped result. If you're computing the index, log it somewhere you'll see it.

    CategoryCoolB Nodes ⚡️

    Inputs (3)

    NameTypeDefaultDescription
    textSTRING—
    delimiterCOMBOnewline3 options: newline, comma, space
    indexINT00–10000—

    Outputs (1)

    NameTypeDescription
    STRINGSTRING—