String Left
The Excel LEFT you didn't know ComfyUI needed
- result
String Left grabs the first N characters of a string - Excel's LEFT, minus the spreadsheet. Give it text and a num_chars, get the leftmost slice back. It's the smallest, plainest node in the TakkunRed ComfyUI-String-Function pack, and together with String Mid and String Right it gives you the three slicing primitives you need to parse text that arrives in a fixed layout.
Where does that actually come up in an image workflow? Fixed-width text. A filename where the batch number is always the first three characters (042_forest.png - take the left 3). A generated tag list where the category prefix is always up front. LLM outputs that follow a strict "X - description" shape, where X is a fixed length you can slice off. When the text is positional, string math beats regex because there's nothing to miscompile.
How it works
It's one Python slice: text[:num_chars]. Nothing clever, nothing surprising - which is exactly the point of a utility node like this. num_chars=0 returns an empty string, and a num_chars larger than the string length just returns the whole string (Python slices clamp gracefully).
One thing to keep in mind: num_chars counts characters, and with a normal Unicode string that means what you'd expect for ASCII, but for multibyte text it counts Unicode code points. If you're slicing a Japanese or emoji-containing string, num_chars=2 takes two characters as a person sees them in most cases - not two raw bytes.
Inputs and outputs
Two required inputs: text (multiline, so pasting a block is fine) and num_chars (INT, default 1, range 0–99999). One output: result (STRING).
The only real decision is the count. Set it once and it's a pure pass-through transform you can drop into a string chain.
Installing it
Same pack, same zero-dependency story:
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 left N characters, not the first N "tokens" or "words." If you want the first word, you want a split on whitespace, not a Left with
num_chars=5. - Positional slicing is brittle - if the layout of your upstream text shifts by one character, every slice silently returns the wrong thing. Reach for String Regex Match when the structure is loose, and for Left/Mid/Right only when it's genuinely fixed.
- There's no trim inside the slice.
"ab c"withnum_chars=3gives you"ab "- if trailing spaces are a problem, run a String Trim after.
For a node this thin, that's it: a slice, an integer, done. It earns its place next to its two siblings, and the three of them together cover every "cut at this position" graph you'll build.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| text | STRING | — | |
| num_chars | INT | 10–99999 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| result | STRING | — |