count
How many times does that substring show up?
- INT
Sometimes "is it in there?" isn't enough. You want to know how many times. If you've got a long string - a raw prompt dump, a pile of tags, file contents read into text - and need to know how often something appears, this is the node.
What it does
count is a wrapper over Python's str.count(substring, start, end). It scans the input string and returns how many non-overlapping times the substring occurs. The start and end inputs let you restrict the search to a slice; the node treats an end of 0 or less as "to the end of the string", so you can ignore them and it just counts everything.
The inputs that matter:
string- what you're searching (required).substring- what you're counting (required).start,end- optional bounds, both defaulting to 0.
Output is an INT. That's the whole deal - no list, no index, just a number.
Why you'd reach for it
Counting is a cheap validation primitive. You can gate a workflow on "does this prompt mention the quality tag at least twice?" by sending the count into a comparison node and testing >= 2. You can detect duplicates before you do something with a list. And it's the natural complement to the pack's in (contains) node: in tells you whether, count tells you how much, find tells you where. Same family, different answer.
Installing
It ships in Basic data handling by StableLlama. In ComfyUI Manager search "Basic data handling" → Install → restart ComfyUI. Or manually:
cd ComfyUI/custom_nodes
git clone https://github.com/StableLlama/ComfyUI-basic_data_handling
Restart. The pack declares zero runtime dependencies - pure Python stdlib - so there's nothing to download and nothing that can conflict with your other nodes.
Where people get burned
Two gotchas, both inherited from Python. First: counts are non-overlapping, so "aaa".count("aa") is 1, not 2 - the first match eats the second's start. Second: it's case-sensitive by default. "Tag" and "tag" count separately; if you want case-insensitive counting, run the string through the pack's casefold node first. Neither is a bug - they're just the semantics you get, and they're the two things that make people think the count is wrong.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| string | STRING | — | |
| substring | STRING | — | |
| startopt | INT | 0 | — |
| endopt | INT | 0 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| INT | INT | — |