Nodes/Vantage-Nodes/Multiline String → Item & Count
ComfyUI Node

Multiline String → Item & Count

Pull one line out of a multiline list by number — and get the count while you're at it

By vantagewithai·Created 8 months ago·Updated 26 days ago· 25
Multiline String → Item & Count
    • string
    • count
    text
    index0
    include_emptyfalse

    The workhorse of prompt-list workflows. You have a multiline list of prompts (or tags, or negative prompts), and you want item number N - a specific one, chosen by a number. This node returns that line and, almost as usefully, the total count of lines in the list. Indexing a list and knowing its length are the two things every list workflow needs, and this node hands you both from one input.

    ComfyUI's core doesn't give you a clean "get line N of a multiline string" node, which is why nearly every serious prompt-variation workflow ends up with one of these. It composes with everything: a random integer upstream gives you a random pick, a stepper gives you next/previous cycling, a scheduler gives you per-batch-index prompts.

    What it needs

    • text - the multiline list.
    • index - which line to return. Zero-based, default 0 (first line).
    • include_empty - whether blank lines are counted as items. Default false, so your list of 1\n2\n\n3 has three items, not four. Flip it on only if blank lines are meaningful entries for you.

    Two outputs:

    • string - the selected line.
    • count - the number of items in the list (after empty-line filtering).

    The count is the sleeper feature. When you're generating per-index prompts in a loop, you need to know when to stop - wire count into a range or a comparison and your workflow can size itself to whatever list you paste in.

    The index quirks to know

    Out-of-range indexes return an empty string rather than erroring - index 7 on a 4-line list gives you "" and count 4. That's lenient but can silently hand an empty prompt to your encoder, so when you're driving the index from something that could overshoot, check the count first. And it's zero-based: the "third" line is index 2. This bites everyone exactly once.

    For a random line, StringListRandom in the same pack is the more direct tool (it handles the seeding for you). Use this node when you have a specific index in mind or a number coming from elsewhere.

    Install

    Part of Vantage-Nodes:

    cd ComfyUI/custom_nodes
    git clone https://github.com/vantagewithai/Vantage-Nodes.git
    pip install -r requirements.txt
    

    or ComfyUI Manager → search "Vantage-Nodes" → Install → restart.

    Common issues

    • Empty string returned - the index is past the end of the list. Use the count output to stay in range.
    • Wrong line picked - zero-based indexing. Your "second" prompt is index 1.
    • Count doesn't match what you pasted - blank lines are being filtered out by include_empty. Turn it on if blanks are intentional items.
    CategoryVantage/String

    Inputs (3)

    NameTypeDefaultDescription
    textSTRING
    indexINT0
    include_emptyBOOLEANfalse

    Outputs (2)

    NameTypeDescription
    stringSTRING
    countINT