JDCN_SplitString
Split a string at the Nth occurrence of a word, from the front or the back
- Prefix
- Suffix
- FoundAt
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 -
frontsearches from the start,rearfrom 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
Occurencein 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.
PNGandpngare different terms. - The README is a little optimistic about which side
IncludeSearchForkeeps 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.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| MainString | STRING | β | |
| SearchFor | STRING | β | |
| StartFrom | COMBO | 2 options: front, rear | |
| Occurence | INT | 11β9999 | β |
| IncludeSearchFor | BOOLEAN | false | β |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| Prefix | STRING | β |
| Suffix | STRING | β |
| FoundAt | INT | β |