rstrip
Rstrip — the trailing-whitespace exterminator for text that came from files
- STRING
If you've ever loaded a text file and found a \n riding on the end of every line, you know why rstrip exists. It removes trailing characters from a string - by default all trailing whitespace, or whatever specific characters you hand it. It's the back-end twin of lstrip, and between the two of them they handle 90% of "my text is dirty at the edges" problems.
Reach for it after loading text from a file or API response, before a string goes into a comparison (trailing whitespace silently breaks equality), or before saving output that shouldn't end in a stray newline. The pack ships file-loading nodes, so the loop "load a string from file → rstrip → use it" is a common pattern.
How it works
Python's str.rstrip(chars). Leave chars empty (the default) and the node treats it as None - strip all trailing whitespace: spaces, tabs, newlines, everything. Give it characters and it strips any of those from the end. Same family rule as lstrip: chars is a set of characters, not a literal suffix.
"hello "→"hello""hello\n"→"hello"(the newline is whitespace, so it goes)"123###".rstrip("#")→"123""hello world".rstrip("dlrow")→"hello "(strips any of those letters from the end)
That last one is the surprise: because chars is a set, rstrip("world") eats every trailing character that happens to be in "world", not the literal word. Use removesuffix for exact suffix removal.
Inputs and outputs
string- required, the text to clean.chars- optionalSTRING, default"". Empty for whitespace mode; otherwise the set of characters to strip from the end.
Output is one STRING - the cleaned copy.
Installing it
Ships in the Basic data handling pack by StableLlama. ComfyUI Manager, search "Basic data handling", install, restart. Manual route:
cd ComfyUI/custom_nodes
git clone https://github.com/StableLlama/ComfyUI-basic_data_handling
Pure Python, zero dependencies, no downloads. Under Basic/STRING in the menu.
Common issues
The set-vs-suffix confusion from lstrip applies here with extra teeth: rstrip("ing") on "walking" doesn't remove the word "ing", it strips every trailing i, n, or g - so "walking" becomes "walk" and "singing" becomes "s". If you need to remove a known literal ending, removesuffix is the correct tool. And in whitespace mode, remember it's all trailing whitespace: a file ending in "\n\n" comes back with both newlines gone, which is usually desired but worth knowing if you were trying to preserve a single line break.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| string | STRING | — | |
| charsopt | STRING | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| STRING | STRING | — |