Nodes/ComfyUI_yanc/๐Ÿ˜ผ> Text Count
ComfyUI Node

๐Ÿ˜ผ> Text Count

Chars, words, or lines from any string in your graph

By ALatentPlaceยทCreated 2 years agoยทUpdated 2 years agoยท 80
๐Ÿ˜ผ> Text Count
    • count
    โ—„textโ€”โ–บ
    โ—„countโ–พโ–บ

    This pack's own Text node bakes in a character count as a bonus output, but it only works on text you typed into that specific node. Text Count is the generalized version: point it at any STRING coming from anywhere in your graph, and pick whether you want characters, words, or lines.

    How it works

    One input, one enum, one number out. Feed it a string, set count to chars, words, or lines, and it returns the corresponding integer. Practical uses: validate that a wildcard or prompt file you loaded actually has the number of lines you expect, sanity-check the length of an LLM node's generated output before it goes anywhere expensive, or feed the count into conditional logic elsewhere in the graph - skip a step if a caption came back empty, for instance.

    It pairs naturally with this pack's own Save Text and Text nodes, but it doesn't care where the string came from - any node in your graph that outputs STRING works as an input here.

    The inputs and outputs that matter

    • text (STRING) - required, any string source.
    • count - enum, one of chars, words, lines.
    • count (INT) out - the result.

    How to install it

    Via ComfyUI Manager: search "yanc" or "ComfyUI_yanc" and install, then restart. Manually:

    cd ComfyUI/custom_nodes
    git clone https://github.com/ALatentPlace/ComfyUI_yanc
    

    then restart ComfyUI. No extra dependencies or model downloads.

    Common issues & troubleshooting

    Word count doesn't match what you'd count by hand in a non-English or CJK text. There's no tokenizer behind this - "words" almost certainly means splitting on whitespace, which is a fine assumption for English-style text and a bad one for languages that don't put spaces between words. Don't rely on this for anything beyond space-delimited text.

    Line count reads as 1 when you expected more. "Lines" counts newline characters, not visual wrapping - a long paragraph that wraps across several rows in a text widget but contains no actual line breaks still counts as a single line. If you need a per-line count for something like a wildcard file, make sure the source actually has real newlines between entries, not just soft wraps.

    You wanted a token count, not a character count. Same caveat as this pack's Text node - chars is a literal character count, and character count doesn't map cleanly onto CLIP/T5 token count. Use this for sanity checks and length limits you defined yourself, not as a proxy for a model's actual token budget.

    CategoryYANC/๐Ÿ˜ผ Text

    Inputs (2)

    NameTypeDefaultDescription
    textSTRINGโ€”
    countCOMBO3 options: chars, words, lines

    Outputs (1)

    NameTypeDescription
    countINTโ€”