String Operations (NH)
Ten string helpers hiding in one dropdown
- text_out
- bool_out
- int_out
Text nodes in ComfyUI are usually one trick each: one node uppercases, one strips, one replaces. String Operations (NH) bundles ten of those tricks into a single node behind an operation dropdown, which is a small thing that saves a lot of canvas space once your workflow has half a dozen text tweaks in it.
Feed it a text string, pick an operation, and read the results off three outputs - text_out (the transformed string), bool_out (a True/False flag), and int_out (a count or length). The ten operations, straight from the dropdown:
- upper, lower, title - case conversion.
- strip - trims surrounding whitespace.
- replace - swaps
param_aforparam_beverywhere. - contains, startswith, endswith - substring tests that land in
bool_out. - length - length of the text in
int_out. - slice - a Python-style slice from
param_a, like2:10,:5, or3:.
The slice syntax is worth a beat, because it's the least obvious one. 2:10 returns characters 2 through 9; :5 returns the first five; 3: returns everything from position 3 on. If you've used Python slicing, it'll feel like home. If you haven't: think "start:end, and blank means the beginning or end." A single number like 4 gives you just that one character.
How to think about it
The node is really three nodes in one, distinguished by which output you read. The case and whitespace ops populate text_out. The tests (contains, startswith, endswith) leave text_out alone and put the verdict in bool_out - which makes it a natural gate for an If/Else or a logic node. The measure ops (length, and to some extent slice) feed int_out. So don't think of it as "one operation," think "which output am I driving."
One quirk: the tests are case-insensitive for contains (it lowercases both sides) but case-sensitive for startswith and endswith. That inconsistency is straight out of the source, so keep it in mind when you're matching a filename or a tag - you'll get different behavior depending on which test you pick.
Install
It's in the NH-Nodes pack:
- ComfyUI Manager → search NH-Nodes → install → restart ComfyUI. Or manually:
cd ComfyUI/custom_nodes
git clone https://github.com/jetthuangai/NH-Nodes.git
cd NH-Nodes
pip install -r requirements.txt
Then restart ComfyUI.
No models, no dependencies beyond the pack's standard ones.
Common issues
The traps here are all about param_a/param_b being empty. For replace, an empty param_a is a no-op; for contains, an empty needle matches anything; for slice, a garbage slice string just returns the text unchanged rather than erroring. Nothing crashes - the node swallows errors and passes text through - which is friendly but means a silent "did nothing" result is usually a bad param, not a bad operation. When in doubt, wire the three outputs to a text display and see which one moved.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| text | STRING | — | |
| operation | COMBO | 10 options: upper, lower, strip, title, replace, contains, +4 | |
| param_aopt | STRING | — | |
| param_bopt | STRING | — |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| text_out | STRING | — |
| bool_out | BOOLEAN | — |
| int_out | INT | — |