NGs String - String Cutter
Truncate long text without chopping a word in half
- Result
The README's own name for this one is "String Cutter," and its blurb gets straight to it: "Text too long but you don't want cut-off words? This node has got you covered." You need to cap a string at N characters - a filename, overlay text, anything feeding into something with a hard limit - and a naive text[:42] slice has a habit of leaving you with "a beautiful sunset over the mountai," mountain chopped mid-word. This node trims to a max length but backs the cut point up to a sensible spot first.
How it works
It cuts text down to maxlength characters, then looks at cut_characters - a set of characters treated as valid break points, ,.- by default - and pulls the cut point back to the nearest one of those instead of leaving a mid-word break. trim strips leading/trailing whitespace from the result. clean (on by default) tidies up any trailing punctuation or whitespace left dangling right at the cut.
The inputs and outputs that matter
text- multiline, the source string.maxlength- default 42, range 1–1024, the hard cap.cut_characters- default,.-, the characters it's allowed to back up to.trim- off by default, strips surrounding whitespace.clean- on by default, tidies dangling punctuation at the cut.
Output is "Result" (STRING).
Where this actually matters in a real workflow: anywhere a generated or user-supplied string is heading somewhere with a real limit - a filename (most filesystems and some cloud storage backends choke past a certain length), an overlay caption burned into an image where too much text just runs off the edge, or a title field in an API call that silently truncates and mangles the last word itself if you don't do it first. Doing the trim yourself, at a sensible boundary, beats letting whatever's downstream do it blindly.
How to install it
ComfyUI Manager: search "NeoGriever," install, restart. Manual:
cd ComfyUI/custom_nodes
git clone https://github.com/NeoGriever/ComfyUI-NeoGriever
then restart. No dependencies, no models.
Common issues & troubleshooting
No valid break point before maxlength. If your text has no comma, period, or dash anywhere within the character budget, there's nothing for the node to back up to - for long unpunctuated sentences, expect either a hard cut or a result that runs slightly past maxlength while it searches for one, rather than a clean mid-word chop. Add a space to cut_characters if you're mostly cutting long, punctuation-light prose - that gives it a break point on nearly every line.
clean=false leaves visible junk. With clean off you'll sometimes see a trailing comma or stray whitespace right at the cut point. Leave it on unless you specifically want the raw, unpolished cut for some downstream reason.
Confusing this with String Squisher. This node discards whatever doesn't fit - it's a truncator. If you actually want to keep all your text and just wrap it into multiple lines instead of losing anything, that's a different node in this pack (NGs String Squisher), not this one.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| text | STRING | — | |
| maxlength | INT | 421–1024 | — |
| cut_characters | STRING | ,.- | — |
| trim | BOOLEAN | false | — |
| clean | BOOLEAN | true | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| Result | STRING | — |