String Length
How long is that string, anyway?
- length
String Length is the measuring tape: one string in, an integer out, telling you how many characters it contains. It's the kind of node that seems pointless until the moment you need it - which is usually the moment you're wondering whether a prompt is reasonable or a filename is about to overflow.
What it is
It runs Python's len(s), which counts characters, not words and not tokens. "hello" returns 5. An empty string returns 0. That's all there is to it.
Where it earns its keep: quick sanity checks. Is an auto-generated prompt from an LLM suspiciously short, or absurdly long? Is a filename within a safe length? Do two strings that should be similar have wildly different sizes, hinting that one is truncated? Wire the integer into a comparison or a display node and you've got a poor man's validator. It's also genuinely useful as a shape check - if you expect a fixed-format string to be exactly 12 characters and it isn't, something upstream broke.
The inputs and outputs
s(STRING) - the text to measure.length(INT) - its length in characters.
One in, one out, no settings.
How to install it
Part of the string-util pack, which is a single dependency-free repo:
cd ComfyUI/custom_nodes
git clone https://github.com/kale4eat/ComfyUI-string-util
or install "ComfyUI-string-util" from ComfyUI Manager and restart. It appears under the string-util category.
Common issues
The one trap is a units confusion: this counts characters, and a character count is not a token count. A rough rule of thumb for English is that tokens run at roughly a quarter to a third of characters, but it varies - don't build a "token budget" node on top of this and expect precision. It's a length check, not a tokenizer. If you're checking prompt lengths against a real token limit, treat this as an approximation and nothing more. (That's not a flaw in the node - it's a flaw in the mental shortcut people want it to be.)
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| s | STRING | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| length | INT | — |