ComfyUI > Nodes > ComfyUI > Substring

ComfyUI Node: Substring

Class Name

StringSubstring

Category
utils/string
Author
ComfyAnonymous (Account age: 872days)
Extension
ComfyUI
Latest Updated
2025-05-13
Github Stars
76.71K

How to Install ComfyUI

Install this extension via the ComfyUI Manager by searching for ComfyUI
  • 1. Click the Manager button in the main menu
  • 2. Select Custom Nodes Manager button
  • 3. Enter ComfyUI in the search bar
After installation, click the Restart button to restart ComfyUI. Then, manually refresh your browser to clear the cache and access the updated list of nodes.

Visit ComfyUI Online for ready-to-use ComfyUI environment

  • Free trial available
  • 16GB VRAM to 80GB VRAM GPU machines
  • 400+ preloaded models/nodes
  • Freedom to upload custom models/nodes
  • 200+ ready-to-run workflows
  • 100% private workspace with up to 200GB storage
  • Dedicated Support

Run ComfyUI Online

Substring Description

Extract specific portion of string based on indices for text manipulation and processing tasks.

Substring:

The StringSubstring node is designed to extract a specific portion of a string based on the indices you provide. This node is particularly useful when you need to isolate a segment of text from a larger string, allowing you to focus on or manipulate just that part. By specifying the starting and ending positions, you can precisely control which part of the string is extracted, making it a powerful tool for text processing tasks. Whether you're working with large blocks of text or need to extract specific data points, the StringSubstring node provides a straightforward and efficient way to achieve this.

Substring Input Parameters:

string

The string parameter is the main text input from which you want to extract a substring. It accepts a string value and can handle multiline text, allowing you to work with complex or lengthy text blocks. This parameter is crucial as it serves as the source from which the substring will be derived.

start

The start parameter specifies the starting index from which the substring extraction will begin. It is an integer value, and the index is zero-based, meaning the first character of the string is at index 0. This parameter determines the position in the string where the extraction starts, and it is essential for defining the beginning of the desired substring.

end

The end parameter defines the ending index for the substring extraction. It is also an integer value and indicates the position in the string where the extraction will stop. The character at this index is not included in the resulting substring. This parameter is important for setting the boundary of the substring, allowing you to control the length and content of the extracted text.

Substring Output Parameters:

string

The output string parameter is the extracted substring from the original input string. This output represents the portion of the text that falls between the specified start and end indices. It is a string value and provides the exact segment of text you intended to isolate, making it useful for further processing or analysis.

Substring Usage Tips:

  • Ensure that the start and end indices are within the bounds of the input string to avoid unexpected results or errors.
  • Use the StringLength node to determine the length of the input string if you're unsure about the appropriate indices to use for extraction.
  • Remember that the end index is exclusive, meaning the character at this position will not be included in the output substring.

Substring Common Errors and Solutions:

IndexError: string index out of range

  • Explanation: This error occurs when the start or end index is outside the range of the input string's length.
  • Solution: Verify that both indices are within the valid range of the string. You can use the StringLength node to check the string's length and adjust the indices accordingly.

ValueError: negative index

  • Explanation: This error happens when a negative index is provided for either the start or end parameter.
  • Solution: Ensure that both indices are non-negative integers. If you need to count from the end of the string, consider using positive indices that reflect the desired position.

Substring Related Nodes

Go back to the extension to check out more related nodes.
ComfyUI
RunComfy
Copyright 2025 RunComfy. All Rights Reserved.

RunComfy is the premier ComfyUI platform, offering ComfyUI online environment and services, along with ComfyUI workflows featuring stunning visuals. RunComfy also provides AI Playground, enabling artists to harness the latest AI tools to create incredible art.