String Rstrip
Trim trailing whitespace and leave the front alone
- string
String Rstrip is the one-sided trimmer that handles the end of a string: trailing spaces, tabs, and newlines get removed, and the front is left exactly as it arrived. It's the answer to the most common piece of text pollution in ComfyUI - the newline that LLM output drags along behind it.
What it is
It runs Python's s.rstrip() - "right strip." "hello world\n" becomes "hello world"; " hello" stays " hello". The trailing newline is exactly the junk that piles up when a chat model finishes a line, so if your text pipeline is "LLM generates prompt → feed to encoder," this node is the lint roller.
It's a natural pair with String EndsWith and other tail-checks: a trailing newline will quietly break an exact suffix match ("world" vs "world\n"), so stripping the end first makes your comparisons honest. When you just want everything clean on both sides, String Strip is the all-in-one; Rstrip is for when only the tail is the problem and the head matters.
The inputs and outputs
s(STRING) - the text to clean.string(STRING) - the same text with trailing whitespace removed.
One in, one out. The mirror image is String Lstrip, also in this pack.
How to install it
Part of the string-util pack, 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 sits under the string-util category.
Common issues
Like all the trims, the only confusion is scope: rstrip touches the end only, so if leading spaces survive, that's correct behavior - reach for String Strip if you want both. And it won't touch interior whitespace, which is also by design. If your text has trailing whitespace plus a bunch of junk in the middle, pair this with String Replace for a full cleanup. No other failure modes worth inventing - it's about as unbreakable as a node gets.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| s | STRING | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| string | STRING | — |