Nodes/ComfyUI-JDCN/JDCN_SplitString
ComfyUI Node

JDCN_SplitString

Split a string at the Nth occurrence of a word, from the front or the back

By daxcayΒ·Created 2 years agoΒ·Updated about a year agoΒ· 159
JDCN_SplitString
    • Prefix
    • Suffix
    • FoundAt
    β—„MainStringβ€”β–Ί
    β—„SearchForβ€”β–Ί
    β—„StartFromβ–Ύβ–Ί
    β—„Occurence1β–Ί
    β—„IncludeSearchForfalseβ–Ί

    Half of file handling is tearing strings apart. C:/frames/render_0001.png - how do you get just the folder, or just the filename, or just the extension? Python's split() does it in a line, but ComfyUI doesn't hand you Python mid-graph. JDCN_SplitString is the string-splitting utility that gives you the two halves and the position of the split, searchable from either end, at any occurrence you choose. It's the pack's answer to "separate the extension from the path" without dragging in a full text-toolkit pack.

    How it works

    You give it a string and a search term. It finds where the term appears, then splits the string there:

    • Prefix - everything before the search term.
    • Suffix - everything after the search term.
    • FoundAt - the character index where the term was found (βˆ’1 if it wasn't found at all).

    The knobs control which occurrence you split on:

    • StartFrom - front searches from the start, rear from the end. Want the last dot in a filename, i.e. the extension? Search from the rear. Want the first slash in a path? Search from the front.
    • Occurence - which instance of the term to use (note the author's spelling; it's Occurence in the node, one 'r'... two, depending on how you count). Default 1 = first match from whichever end you chose.
    • IncludeSearchFor - when on, keeps the search term attached to one side of the split instead of dropping it. In the shipped code it glues the term to the front/prefix side; the README describes it as going to the suffix, so if you're relying on exactly which side gets it, test once with a sample string.

    Where it fits

    The README shows the three canonical uses, and they're the ones you'll actually hit: separate name.png into name and png, split a full path into directory and filename, and "go up a folder" by splitting off the trailing directory. Because the JDCN file nodes all speak paths, SplitString is the natural companion when you need to derive a sibling path or rename convention from one that already exists.

    Install

    Comes with 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
    

    Only pack dependency is piexif; nothing heavy to fetch.

    Gotchas

    • Not found - if the search term isn't in the string, the whole string comes back as Prefix, Suffix is empty, and FoundAt is βˆ’1. That's by design, not a bug - handy for branching, but it'll surprise you the first time.
    • Empty search term - returns empty strings and 0. If you're seeing blank outputs, check you actually typed the term.
    • It's case-sensitive. PNG and png are different terms.
    • The README is a little optimistic about which side IncludeSearchFor keeps the term on. Test with a quick run rather than assuming.

    Tiny node, but string surgery is 20% of every automation workflow, and this is the cleanest way to do it inside this pack without bolting on a separate text-utility install.

    CategoryπŸ”΅ JDCN πŸ”΅

    Inputs (5)

    NameTypeDefaultDescription
    MainStringSTRINGβ€”
    SearchForSTRINGβ€”
    StartFromCOMBO2 options: front, rear
    OccurenceINT11–9999β€”
    IncludeSearchForBOOLEANfalseβ€”

    Outputs (3)

    NameTypeDescription
    PrefixSTRINGβ€”
    SuffixSTRINGβ€”
    FoundAtINTβ€”