段落提取指定索引行🐠meeeyo.com
Pull a range or a set of lines and rejoin them into one string
- STRING
ExtractAndCombineLines grabs a subset of lines out of a text block and stitches them back together into a single STRING. It's the "select and merge" sibling of ExtractSpecificLines in the MeeeyoAI/ComfyUI_StringOps pack: that node splits the picks into separate outputs, this one combines them into one.
The typical job is slimming a multi-line prompt block. You have a template with ten lines - subject, style, lighting, camera, quality tags, and a few sections you don't want this run - and you want lines 2 through 4 as a compact prompt. Type 2-4 and out comes those three lines joined with newlines.
The inputs
- input_text - the multiline block to pull from.
- line_indices - the selector, and it's more flexible than it looks. Default
2-3. Two formats:2-3- an inclusive range. Clamps gracefully: asking for2-99when the block has 4 lines just gives you what exists.2|4|6- individual 1-based line numbers, pipe-separated, picked in the order you list them.
The output
One STRING - the selected lines joined with newlines, in selection order. So 3|1 returns line 3 first, then line 1. That ordering quirk is worth knowing: the output follows your input order, not document order.
The gotchas
- Indexing is 1-based, consistent with the rest of this pack. Line 1 is the first line. Ask for line 0 and you get an empty result - silently.
- Out-of-range requests are dropped, not errors.
2-4on a 3-line block gives you lines 2 and 3. Combined with the silent failure on bad input, a mistyped selector can quietly produce an empty string. - The join is always newline. If your downstream needs commas (say, you're building a comma-separated prompt fragment), run the result through BatchReplaceStrings with a rule like
\n|,to swap the separators - a two-node combination that covers most "rejoin with different glue" needs.
It pairs well with the pack's other line tools: FilterLinesBySubstrings narrows by content, this one narrows by position, and RandomLineFromText picks from the result if you want a random draw from an already-filtered pool.
Installing
Standard pack install:
cd ComfyUI/custom_nodes
git clone https://github.com/MeeeyoAI/ComfyUI_StringOps.git
or via ComfyUI Manager searching ComfyUI_StringOps, then restart. Under "Meeeyo/String". No models, no dependencies to install.
A clean, deterministic selector with one flexible input. If you structure prompts as labeled line blocks - a style that works well with this pack - this is the node that pulls out exactly the section you want and hands it back ready to encode.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| input_text | STRING | — | |
| line_indices | STRING | 2-3 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| STRING | STRING | — |