Nodes/Bulent Gercek Nodes/String Line Count
ComfyUI Node

String Line Count

How many lines is that list, really? — String Line Count in ComfyUI

By bulentgercek·Created 2 days ago·Updated a day ago· 1
String Line Count
    • count
    text
    skip_emptytrue

    String Line Count is the support act to the rest of the bulentgercek-nodes pack, and support acts matter. It takes a string, counts the lines in it, and hands you an integer. That's the whole node - one input, one output, no state, no surprises. It's the kind of tiny utility you install for someone else's node and then find yourself reaching for constantly.

    You give it text (multiline) and it returns count (INT). The skip_empty toggle defaults to on, meaning blank lines don't count. The text input is a forced input, which is ComfyUI's way of saying it accepts a wire as happily as typed text - so feed it the string output of a List Pick node, the joined output of a Prompt Builder, or any primitive string, and it'll count whatever actually flows through the graph rather than what you remember typing.

    Why you'd reach for it

    Three jobs, in order of how often you'll hit them:

    • Drive batch size. Wire count into the batch size of your latent node and you get "one image per line in this list." Pair it with List Pick on increment and a batch of five prompt variations generates exactly five images, no more, no fewer - you never under-queue and wonder where image four went.
    • Guard against empty. If a workflow builds its prompt from user input or an upstream text node, a zero count tells you the source came up empty before you burn a generation on a blank prompt. Combined with a switch or comparison node it's a cheap "skip this if there's nothing to say" check.
    • Debug your own lists. You're sure that multiline box has eight entries but the picker keeps behaving like it has seven. Count it and find out. This is usually where a stray blank line or a list that was pasted with one giant line break gotcha is hiding.

    How it counts

    The implementation is honest and simple: split the text on newlines (it uses Python's splitlines(), so \r\n Windows line endings don't trip it up) and, if skip_empty is on, drop lines whose content is only whitespace. Two details worth internalizing. First, whitespace-only lines count as empty, so a line of spaces isn't a real line - good or bad depending on whether you were using blank lines as separators. Second, there's no phantom trailing line: a string ending in a newline doesn't get a bonus count, so no off-by-one at the end. An empty string returns 0.

    The one thing that trips people is that skip_empty defaults to on. If you paste a list with intentional blank separator lines and wonder why the count disagrees with the line numbers in your text editor, that toggle is the culprit. Flip it off and blank lines count too.

    Install

    It ships in bulentgercek/bulentgercek-nodes under the bulentgercek/text category. Install via ComfyUI Manager (search "bulentgercek") or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/bulentgercek/bulentgercek-nodes
    

    then restart ComfyUI. The pack has zero dependencies and downloads nothing - it's plain Python doing string math, which is why it's so unbothered. In a world of nodes that drag in half of PyPI, that's quietly refreshing. You won't build a workflow around String Line Count, but the workflows you build around its siblings will lean on it more than you expect.

    Categorybulentgercek/text

    Inputs (2)

    NameTypeDefaultDescription
    textSTRING
    skip_emptyBOOLEANtrue

    Outputs (1)

    NameTypeDescription
    countINT