String Get Line
Pull one line out of a multiline string
- STRING
You've got a block of text with several lines - a list of prompts, one per line, say - and you want just one of them. This node grabs the line at the index you give it and outputs that single line. Line 0 is the first, line 1 the second, and so on.
The reason this is more than a curiosity: it turns a multiline text box into a little prompt list you can index into. Put ten prompts in a JWStringMultiline (or any multiline string), then drive line_index from a counter or a batch number, and each run pulls a different prompt. That's a poor-man's prompt-scheduler built out of two nodes - genuinely handy for generating variations from a fixed list without rewiring anything between runs.
How it works
It splits the source on newlines and returns the line at the given index. Zero-based, so index 0 is the first line.
Inputs and outputs
- source - the multiline string to read from.
- line_index - which line to pull, starting at 0. Negative indices count from the end (Python-style: -1 is the last line), since the input accepts negative numbers.
Output is a single STRING, the selected line.
Installing it
It's in the pack's comfyui_primitive_ops file. Install via ComfyUI Manager (search Various ComfyUI Nodes by Type / comfyui-various) or clone:
cd ComfyUI/custom_nodes
git clone https://github.com/jamesWalker55/comfyui-various
Restart ComfyUI. No models, no extra dependencies.
Common issues
The classic off-by-one: it's zero-indexed. The first line is 0, not 1. If you're getting the line after the one you wanted, that's why.
The other real risk is asking for a line that isn't there. Point line_index past the last line and there's nothing to return - it'll error. If you're driving the index from a counter that keeps climbing, it will eventually run off the end unless you wrap it around. The clean pattern is to keep the index within range with a modulo against the number of lines, so the counter cycles through the list instead of falling off it - that turns "pick line N" into "loop through the list forever," which is usually what you actually wanted.
Also watch for blank lines and trailing whitespace in your text box - an empty line still counts as a line and will come back as an empty string, which can look like the node "not working" when it's doing exactly what you asked.
If it loads red as missing in a shared workflow, install the pack via Manager's "Install Missing Custom Nodes" or clone the repo.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| source | STRING | — | |
| line_index | INT | 0-18446744073709550000–18446744073709550000 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| STRING | STRING | — |