✂️ String Text Splitter
Cut a String at the First Delimiter and Keep Both Halves
- first_chunk
- remainder
- chunk_list
- targeted_chunks
✂️ String Text Splitter splits a string on its first delimiter and gives you the front, the back, and the full list of pieces. On its own that sounds like a solution looking for a problem, and then you meet a real one: the metadata extractor in this same pack returns filtered_params_list as one value per line, and you need value three on its own. Or a filename like style__subject__seed.png and you want the middle. Or a prompt written as subject | style | camera that you want broken into branches.
How it works
Give it delimiter and it splits there. Two ordinary splits happen at once: one limited to the first occurrence (feeding first_chunk and remainder), and one unlimited (feeding chunk_list). part1|part2|part3 split on | gives part1, then part2|part3 as the remainder, then all three as a list. The delimiter is regex-escaped before use, so characters like . * [ behave as literal characters - no accidental pattern matching.
split_at_linebreaks adds line breaks as a second split point, and works with or without a delimiter set: delimiter only, newlines only, or both. With both, either will cut. Handy for feeding a multi-line box into per-line outputs.
target_indices takes a comma-separated list of 0-based indices and returns those chunks, one per line, in a single string. 0,2 gives you the first and third. Out-of-range indices are simply skipped, and a malformed list prints a warning to the console and skips extraction rather than failing the run - so an empty targeted_chunks usually means a typo.
One behaviour to know before you index into anything: empty pieces are dropped from chunk_list. Two delimiters in a row (a||b) produce a and b, not a blank in the middle, so indices are positions among non-empty chunks. That's usually what you want and it will occasionally surprise you.
If neither a delimiter nor linebreaking is active, the node passes the input straight through as first_chunk with an empty remainder and a single-item list.
Inputs and outputs
Required inputs: input_string, delimiter, split_at_linebreaks (boolean), target_indices (string, can be empty). Outputs: first_chunk, remainder, chunk_list, targeted_chunks.
first_chunk and remainder are the pair to reach for when there's exactly one meaningful delimiter in the string. chunk_list is for anything list-aware. targeted_chunks is for grabbing specific fields without extra nodes - and it's the one that pairs with the metadata extractors, whose filtered output is a newline-per-value string.
Install
ComfyUI Manager → search "ComfyUI-mnemic-nodes" → install → restart. Or:
cd ComfyUI/custom_nodes
git clone https://github.com/MNeMoNiCuZ/ComfyUI-mnemic-nodes
No downloads or keys. The pack's requirements.txt covers its other nodes.
Common issues
Remainder is empty. There's only one delimiter occurrence, so the "after" part is nothing. That's correct.
targeted_chunks comes back blank. Check the index range and the format - 0, 2 with a space is fine, 0;2 isn't. Watch the console for the format warning.
Off-by-one when grabbing a specific field. You're counting empty chunks that the node dropped. Split into chunk_list, look at it, then index.
Nothing splits. Delimiter is empty and split_at_linebreaks is off, or the delimiter isn't in the string at all. A literal escape like \n typed into the box is two characters, not a newline - use the linebreak toggle instead.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| input_string | STRING | The input text to split. | |
| delimiter | STRING | The character to split the text on. The node will split at the first time this character appears. | |
| split_at_linebreaks | BOOLEAN | false | If true, also split at line breaks. Can be used with or without a delimiter. |
| target_indices | STRING | Comma-separated list of indices (0-based) of chunks to extract. E.g., '0,2' for the first and third chunk. Leave empty to ignore. |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| first_chunk | STRING | The part of the string before the first delimiter. |
| remainder | STRING | The remainder string after the first delimiter. |
| chunk_list | STRING | A list of all items split by the delimiter. |
| targeted_chunks | STRING | A multiline string of chunks at the specified target indices. |