String Right
Grab the last N characters — the filename extension end of the pack
- result
String Right returns the last N characters of a string - Excel's RIGHT, ported to a node. It's the bookend of the slicing trio (Left / Mid / Right) in the TakkunRed ComfyUI-String-Function pack, and it's the natural tool for the "tail" of anything: file extensions, trailing IDs, the end of a filename that carries the meaningful bit.
In practice it earns its keep on things like image_00042.png → take the last 3 for png, or a generated string where the version tag always sits at the end. When the interesting part of your text is anchored to the end rather than the start, Right beats Left-and-then-reverse, because there's no reversing at all.
How it works
One Python slice: text[-num_chars:], with the guard that num_chars=0 returns an empty string instead of the whole string (which is what text[-0:] would naively give you). The author handled that edge case explicitly, which is a small sign of care. Slices clamp, so asking for more characters than the string has just returns the whole thing.
Like its siblings, num_chars counts characters, not bytes - multibyte text slices along character boundaries as a human reads them, not along raw byte offsets.
Inputs and outputs
Two required inputs: text and num_chars (INT, default 1, 0–99999). One output: result (STRING).
Nothing else to configure. It's a pure transform, the kind of node you drop into a chain and forget about.
Installing it
Same pack, same zero-dependency install:
cd ComfyUI/custom_nodes
git clone https://github.com/TakkunRed/ComfyUI-String-Function
Or search "ComfyUI-String-Function" in ComfyUI Manager, restart, and it's under String Function.
Where people get burned
- It's the last N characters, not the last "word" or "segment." The classic trap: grabbing a file extension with
num_chars=3fromphoto.jpeggives youjpeg- fine - but fromphoto.pngyou getpng- also fine - and fromarchive.tar.gzyou get.gz, nottar.gz. If you want the part after the last dot, that's a Split on.withuse_last=True, not a Right. - Trailing whitespace counts. If your upstream text has a stray newline, it eats a character of your count. A String Trim upstream fixes that.
- There's no "last 5 non-space characters" mode - the count is literal.
It's a three-line node, and that's the point: when you need the tail, this is the two-second answer, and it composes cleanly with String Find and Mid for anything fancier.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| text | STRING | — | |
| num_chars | INT | 10–99999 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| result | STRING | — |