ComfyUI > Nodes > ComfyUI > Trim

ComfyUI Node: Trim

Class Name

StringTrim

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

Trim Description

Clean up text by removing unwanted whitespace, enhancing readability and consistency for text data.

Trim:

The StringTrim node is designed to help you clean up your text by removing unwanted whitespace from your strings. This node is particularly useful when you need to ensure that your text data is tidy and free from leading, trailing, or both types of spaces that might have been inadvertently added during data entry or processing. By using this node, you can enhance the readability and consistency of your text, which is crucial for both aesthetic and functional purposes, such as preparing data for further processing or ensuring uniformity in text presentation. The StringTrim node offers flexibility by allowing you to choose whether to trim spaces from both ends of the string, just the left side, or just the right side, making it a versatile tool for text manipulation.

Trim Input Parameters:

string

The string parameter is the text input that you want to trim. It can be a single line or multiline string, and the node will process it to remove unwanted spaces based on the selected mode. This parameter is crucial as it determines the content that will be cleaned up.

mode

The mode parameter allows you to specify how the trimming should be applied to the input string. It offers three options: "Both", "Left", and "Right". "Both" will remove spaces from both the beginning and end of the string, "Left" will remove spaces only from the start, and "Right" will remove spaces only from the end. This parameter is essential for customizing the trimming operation to suit your specific needs.

Trim Output Parameters:

string

The output string is the result of the trimming operation. It is the cleaned-up version of the input string, with spaces removed according to the selected mode. This output is important as it provides you with a neatly formatted string, ready for further use or display.

Trim Usage Tips:

  • Use the "Both" mode when you want to ensure that your string is free from any leading or trailing spaces, which is common when preparing data for storage or display.
  • If you are dealing with text that should align to the left, such as in a list or table, use the "Left" mode to remove any leading spaces that might disrupt the alignment.
  • For text that should align to the right, such as numbers in a financial report, use the "Right" mode to remove trailing spaces and ensure proper alignment.

Trim Common Errors and Solutions:

Invalid mode selection

  • Explanation: The mode selected is not one of the available options ("Both", "Left", "Right").
  • Solution: Ensure that the mode parameter is set to one of the valid options. Double-check the spelling and case sensitivity of the mode value.

Empty string input

  • Explanation: The input string is empty, resulting in no visible change after trimming.
  • Solution: Verify that the input string contains text. If the string is intentionally empty, no action is needed, but if not, ensure the correct string is being passed to the node.

Trim 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.