- before
- after
String Split cuts a string in two at a delimiter and hands you the piece before it and the piece after it. "masterpiece, 1girl" with delimiter ", " gives you masterpiece and 1girl. It's the key:value parser of the TakkunRed ComfyUI-String-Function pack, and it's the node you reach for when text arrives as name: value, category - description, or file.txt and you need both sides as separate wires.
The reason it beats a full regex for most jobs is that it's a binary split - two outputs, before and after - not a list explosion. If you only ever need the first segment and the rest, or the part before a marker and the part after, this is a one-node answer with nothing to count. Pair it with String Find or String Regex Match for anything more structured.
How it works
It finds a delimiter and splits at it, with two controls over which delimiter when there are several:
occurrence(default 1) - split at the Nth delimiter.occurrence=2splits at the second,rather than the first.use_last(default False) - instead of the Nth, split at the last occurrence of the delimiter. This is the classic "get the part after the final dot" move for filenames:archive.tar.gzsplit on.withuse_last=Truegives youarchive.tarandgz.
The behavior when the delimiter isn't found is deliberate and worth remembering: the whole text comes back as before, and after is empty. No error, no crash - just both outputs still defined, which keeps downstream nodes from red-lining.
Inputs and outputs
Required: text and delimiter. Optional: occurrence (1–999) and use_last. Outputs:
before(STRING) - the part up to (not including) the delimiter.after(STRING) - the part after (not including) the delimiter.
Both exclude the delimiter itself - there's no "keep the separator" mode, so if you need the delimiter preserved you'll concatenate it back in downstream.
Installing it
Same pack, same zero-dependency story:
cd ComfyUI/custom_nodes
git clone https://github.com/TakkunRed/ComfyUI-String-Function
Or search "ComfyUI-String-Function" in ComfyUI Manager, restart, and it's under String Function.
Where people get burned
- Delimiter not found silently means "no split." The whole string lands in
beforeandafteris empty - useful, but if you expected a split to happen and it didn't, check the delimiter spelling (including the space before/after it). - An empty delimiter returns the text whole. The source guards this:
delimiter=""gives youbefore=text,after="". - It splits at the first occurrence by default.
"a,b,c"with","givesaandb,c- theafterstill contains the rest of the list. If you want every piece, chain a couple of these or use String Regex Match'sfindall. use_lastignoresoccurrence. They're two different ways to pick which delimiter; setting both is allowed butuse_lastwins. The tooltip says as much.
For key: value parsing out of an LLM's structured output, or peeling a filename apart, it's the two-wire answer - and use_last=True is worth memorising on its own.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| text | STRING | — | |
| delimiter | STRING | — | |
| occurrenceopt | INT | 11–999 | 何番目の区切り文字で分割するか (use_last が True のときは無視) |
| use_lastopt | BOOLEAN | false | True にすると最後に出現した区切り文字で分割する |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| before | STRING | — |
| after | STRING | — |