Nodes/ComfyUI Ino Nodes/Ino String Slice
ComfyUI Node

Ino String Slice

Slice a string by index — Python style, gotcha included

By nobandegani·Created about a year ago·Updated 2 months ago· 6
Ino String Slice
    • string
    input_string
    start0
    end0

    If you've ever wanted to pull "midjourney" out of "midjourney_0001.png" without a regex, Ino String Slice is your node. It extracts a substring by start and end index and returns it as a plain string. Python users will feel right at home; everyone else needs the one paragraph of context below.

    The inputs are input_string, start, and end, both indexes being INTs from 0 up. Indexing is zero-based: the first character is position 0. input_string[0:3] gives you the first three characters. That's the entire mechanism - it's Python slicing with a couple of guard rails bolted on.

    The gotcha that will catch you

    end defaults to 0, and the node treats 0 as "to the end of the string." So with start=5, end=0, you get everything from position 5 onward. That's a deliberate convenience - "slice from here to the end" is the most common ask - but it's also exactly backwards from what you'd expect if you're used to other slice tools, where 0:0 means an empty string.

    So: want the tail? Leave end at 0. Want a specific span? Set end to something > 0 and the output is input_string[start:end]. Want the first N characters? Set start=0 and end=N. The end input has a min of 0, so you can't express "negative index" here - if you're slicing from the end, flip to InoStringSplit or trim first. One light aside: yes, the authors could have named it "SliceToEndWhenZero"; they didn't, so this paragraph is your documentation.

    What it's for

    Stripping extensions ([: -4]-style operations), pulling IDs out of generated filenames, cutting a caption down to its first sentence. Feed the result into InoStringContains or a concat and you've got real text processing in the graph.

    Installing Ino Nodes

    Part of the Ino pack - install once, use it and its 125 siblings. ComfyUI Manager: search "ComfyUI Ino Nodes", install, restart. Terminal:

    cd ComfyUI/custom_nodes
    git clone https://github.com/nobandegani/ComfyUI-InoNodes.git
    cd comfyui_ino_nodes
    pip install -r requirements.txt
    

    Needs inopyutils in ComfyUI's Python environment, V3-schema pack so keep ComfyUI current. Nothing else.

    Where people get burned

    Just the end=0 behavior. If a slice is coming back longer than you expected, you almost certainly left end at its default thinking it meant "zero characters." Set it explicitly and the mystery evaporates.

    CategoryInoStringHelper

    Inputs (3)

    NameTypeDefaultDescription
    input_stringSTRING
    startINT00–99999
    endINT00–99999

    Outputs (1)

    NameTypeDescription
    stringSTRING