Nodes/ComfyUI-JDCN/JDCN_StringManipulator
ComfyUI Node

JDCN_StringManipulator

Slice, shuffle, and rejoin prompts and tags

By daxcayΒ·Created 2 years agoΒ·Updated about a year agoΒ· 159
JDCN_StringManipulator
    • text
    • index_from
    • index_to
    • batch_size
    β—„textconceptβ–Ί
    β—„index0β–Ί
    β—„index_changeβ–Ύβ–Ί
    β—„orderβ–Ύβ–Ί
    β—„separatorβ–Ύβ–Ί
    β—„custom_separatorNAβ–Ί
    β—„batch_size1β–Ί
    β—„joinerβ–Ύβ–Ί
    β—„custom_joinerNAβ–Ί
    β—„space_before_joinfalseβ–Ί

    Some nodes do one thing; this one is a pocket knife for text lists. JDCN_StringManipulator takes a block of text, splits it on whatever separator you like, picks a handful of items out of it - from the top, from the bottom, or at random - and rejoins them with a different separator. The classic use: you've got a big comma-separated tag list or a pile of prompt fragments, and you want to grab a specific slice of it each run to feed a sampler. That's this node's entire reason to exist.

    How it works

    The flow is split β†’ select β†’ join, with a knob at every step:

    1. Split your text using separator (Comma, Semicolon, Pipe, Hyphen, Colon, Space, Tab, Newline, and more, plus a Custom option where you type your own in custom_separator). Everything is trimmed of whitespace.
    2. Select batch_size items. order decides how: toptobottom takes items starting at index; bottomtotop walks the list reversed; random pulls a random sample. The index_change option (fixed/increment/decrement/random) is declared on the node, but in the shipped code it doesn't actually do anything yet - selection is driven by index and order. Don't build logic around it until an update wires it up.
    3. Join the selected items using joiner (same menu, or a custom_joiner). space_before_join adds a space after the joiner - useful when you're gluing with commas for prompt syntax.

    Outputs

    • text - the final re-joined string.
    • index_from and index_to - the range of source indices you just pulled (for random order these are informational, not the actual sampled indices).
    • batch_size - echoed back so downstream nodes can see the batch size without a separate constant.

    The node returns ("Index error", 0, 0, 0) if the selected range is empty - e.g. index beyond the end of the list. It won't crash, but you'll see "Index error" in the text output and should widen the range.

    Where it fits

    • Cycling through a saved list of prompt fragments, one batch per queue, for variation runs.
    • Pulling K random tags from a big tag pool for dataset-style exploration or wildcard-style prompt construction.
    • Chunking a caption list before saving it with JDCN_TXTFileSaver.

    If your workflow already has a text-utility pack like rgthree or a Python expression node, you may not need this. But it's self-contained and does the one thing - "give me a slice of this text list" - without dependencies.

    Install

    Part of ComfyUI-JDCN. ComfyUI Manager β†’ Install Custom Nodes β†’ search "JDCN", or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/daxcay/ComfyUI-JDCN.git
    pip install -r requirements.txt
    

    Pack dependency is just piexif. No models.

    Gotchas

    • Order matters - bottomtotop reverses before slicing, so index counts from the end. Getting "the last 3" requires bottomtotop with index=0, not a negative index (there are none here).
    • Custom separators default to NA - if you pick Custom and leave it at the default, the split behaves oddly. Type an actual separator.
    • Index error strings - an out-of-range selection doesn't fail the queue; it quietly emits "Index error" text. In a long automation run, that can pollute a prompt with literal words. Watch for it.
    CategoryπŸ”΅ JDCN πŸ”΅

    Inputs (10)

    NameTypeDefaultDescription
    textSTRINGconceptβ€”
    indexINT0β€”
    index_changeCOMBO4 options: fixed, increment, decrement, random
    orderCOMBO3 options: toptobottom, bottomtotop, random
    separatorCOMBO15 options: Comma, Semicolon, Pipe, Hyphen, Colon, Period, +9
    custom_separatorSTRINGNAβ€”
    batch_sizeINT1β€”
    joinerCOMBO15 options: Comma, Semicolon, Pipe, Hyphen, Colon, Period, +9
    custom_joinerSTRINGNAβ€”
    space_before_joinBOOLEANfalseβ€”

    Outputs (4)

    NameTypeDescription
    textSTRINGβ€”
    index_fromINTβ€”
    index_toINTβ€”
    batch_sizeINTβ€”