ComfyUI Node

Text Line Count

The three-line node that makes multiline text useful

By kenyonxu·Created 4 months ago·Updated 3 months ago· 0
Text Line Count
    • count
    text

    Text Line Count is the kind of node you don't think you need until you're halfway through building a workflow that should do something once per line. It takes a multiline string and hands you back an integer: how many lines are in it.

    One input, one output. text is a multiline string widget; count is an INT. That's the whole thing. The implementation is literally three lines - it counts newline characters and adds one, and empty input returns 0.

    So when does that matter? Whenever a count is the missing piece of your graph. Paste a batch of prompts into a multiline box and let this node's output drive a loop count or batch size, and your workflow iterates exactly as many times as you have items instead of "run once, manually change the prompt, run again." That's the pattern: a few lines of text become a loop bound, which is the difference between babysitting a workflow and letting it run.

    The one thing to know: because the count is newlines + 1, a trailing newline is a phantom extra line. If your text box ends with a carriage return, count comes back one higher than the items you actually see. It only costs you one wasted iteration, but trim trailing newlines if you're being precise.

    Also be aware it counts lines, not comma-separated items. It lives in the same pack as Kai Civitai LoRA Loader, and that node's trigger-word output is comma-joined - so don't expect this to count that string's words. For multiline prompt lists, though, it's exactly right.

    Install is the same one-clone-for-everything deal as the rest of the pack:

    cd ComfyUI/custom_nodes
    git clone https://github.com/kenyonxu/ComfyUI_KaiUtilities.git
    

    Restart ComfyUI and it appears under KaiUtilities/text. Tiny, boring, and precisely the thing you'd rather have than hand-counting a 40-item prompt list.

    CategoryKaiUtilities/text

    Inputs (1)

    NameTypeDefaultDescription
    textSTRING

    Outputs (1)

    NameTypeDescription
    countINT