lstrip
Lstrip — cut the junk off the front of your strings
- STRING
Text that comes from a file, an API, or a shared workflow tends to accumulate leading junk: spaces, tabs, newlines, the occasional stray character. lstrip removes whatever's hanging off the front of a string. By default that's all leading whitespace; give it a chars argument and it strips any of those characters instead.
You'd reach for it when cleaning loaded text before it's processed - trimming the leading whitespace off a line you read from a file, stripping an unwanted # off a comment line, or normalizing input so a comparison or parse downstream gets clean text. It's the front-end twin of rstrip, and both are usually applied in the same cleanup chain.
How it works
Python's str.lstrip(chars), with one deliberate behavior built into the node: if you leave chars empty (the default), it becomes None, which means "strip all leading whitespace" - spaces, tabs, newlines, the works. If you do provide chars, it's treated as a set of characters, not a prefix. lstrip("ab") strips any leading a or b, in any mix - it won't just remove the literal substring "ab".
Examples: " hi" → "hi". "\n\tprompt" → "prompt". "###note".lstrip("#") → "note".
Inputs and outputs
string- required, the text to clean.chars- optionalSTRING, default"". Leave empty for whitespace-stripping mode; fill it with the specific characters to remove.
Output is one STRING - the cleaned copy.
Installing it
Part of the Basic data handling pack by StableLlama. ComfyUI Manager, search "Basic data handling", install, restart. Or:
cd ComfyUI/custom_nodes
git clone https://github.com/StableLlama/ComfyUI-basic_data_handling
Pure Python, no dependencies, no downloads - installs clean, which is the pack's calling card. Under Basic/STRING in the menu.
Common issues
The set-vs-prefix confusion is the big one. People type chars="ab" expecting to remove the exact word "ab" from the front, and instead get every leading a and b stripped. If you want an exact prefix removed, use the pack's removeprefix node instead - that's the literal one. Also note that in whitespace mode lstrip removes all leading whitespace including newlines, so if you only wanted to remove a single trailing newline, this will happily eat an entire indentation block too. That's usually what you want when cleaning text, just don't be surprised by the enthusiasm.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| string | STRING | — | |
| charsopt | STRING | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| STRING | STRING | — |