Trim
Removes specified characters from the beginning and/or end of a string.
Common Properties
- Name - The custom name of the node.
- Color - The custom color of the node.
- Delay Before (sec) - Waits in seconds before executing the node.
- Delay After (sec) - Waits in seconds after executing node.
- Continue On Error - Automation will continue regardless of any error. The default value is false.
info
If the ContinueOnError property is true, no error is caught when the project is executed, even if a Catch node is used.
Inputs
- String - The string to trim.
- Cut Set - Characters to remove from the edges. If empty, removes whitespace (spaces, tabs, newlines).
Options
- Trim Type - Specifies which sides to trim from:
Left Trim- Remove characters from the beginning onlyRight Trim- Remove characters from the end onlyLeft + Right Trim- Remove characters from both sides (default)
Output
- Result - The trimmed string.
How It Works
The Trim node removes specified characters from string edges based on the trim type:
When Cut Set is empty:
- Removes whitespace characters: spaces, tabs (
\t), newlines (\n), carriage returns (\r) - Uses
Left + Right Trimmode (ignores Trim Type option)
When Cut Set is specified:
- Removes any characters that appear in the Cut Set string
- Respects the Trim Type option (Left, Right, or Both)
- Removes characters from edges only, not from the middle
Usage Examples
Example 1: Trim Whitespace (Empty Cut Set)
- String:
" Hello World " - Cut Set:
""(empty) - Result:
"Hello World"
Example 2: Trim Specific Characters from Both Sides
- String:
"###Hello###" - Cut Set:
"#" - Trim Type:
Left + Right Trim - Result:
"Hello"
Example 3: Left Trim Only
- String:
"000123" - Cut Set:
"0" - Trim Type:
Left Trim - Result:
"123"
Example 4: Right Trim Only
- String:
"Price: $99.00" - Cut Set:
"0" - Trim Type:
Right Trim - Result:
"Price: $99."
Example 5: Trim Multiple Characters
- String:
"...Hello!!!" - Cut Set:
".!" - Trim Type:
Left + Right Trim - Result:
"Hello"
Tips
- Leave Cut Set empty for standard whitespace trimming
- Cut Set removes any of the specified characters, not the exact string
- Great for cleaning user input
- Use before parsing or validation
- Removes from edges only - middle characters are preserved
- Combine with Replace to remove characters from anywhere
Common Errors and Solutions
Error: Characters not removed from middle
- Cause: Trim only works on edges, not middle
- Solution: Use Replace node to remove characters from anywhere
Error: Unexpected results with Cut Set
- Cause: Cut Set removes ANY of those characters, not the exact sequence
- Solution: Each character in Cut Set is treated individually
Practical RPA Examples
Example: Clean User Input
String: " john.doe@example.com "
Cut Set: "" (empty)
Result: "john.doe@example.com"
Use: Remove accidental spaces from form input
Example: Remove Leading Zeros
String: "000123"
Cut Set: "0"
Trim Type: Left Trim
Result: "123"
Use: Convert string number with leading zeros
Example: Clean CSV Data
String: " Product Name "
Cut Set: "" (empty)
Result: "Product Name"
Use: Clean whitespace from CSV fields
Example: Remove Quotes
String: '"Hello World"'
Cut Set: '"'
Trim Type: Left + Right Trim
Result: "Hello World"
Use: Remove surrounding quotes from strings
Example: Clean File Path
String: "///path/to/file///"
Cut Set: "/"
Trim Type: Right Trim
Result: "///path/to/file"
Use: Remove trailing slashes
Example: Remove Punctuation from Edges
String: "...Great product!!!"
Cut Set: ".!"
Result: "Great product"
Use: Clean text for analysis
Trim Type Detailed Examples
Left Trim
Removes characters from the beginning only:
String: "<<<Data>>>"
Cut Set: "<>"
Trim Type: Left Trim
Result: "Data>>>"
Right Trim
Removes characters from the end only:
String: "<<<Data>>>"
Cut Set: "<>"
Trim Type: Right Trim
Result: "<<<Data"
Left + Right Trim
Removes characters from both ends:
String: "<<<Data>>>"
Cut Set: "<>"
Trim Type: Left + Right Trim
Result: "Data"
Whitespace Trimming (Empty Cut Set)
When Cut Set is empty, removes all whitespace:
Removes:
- Spaces: " "
- Tabs: "\t"
- Newlines: "\n"
- Carriage returns: "\r"
Example:
String: " \n\tHello\t\n "
Cut Set: ""
Result: "Hello"
Pattern: Input Validation Pipeline
Clean and validate user input:
Step 1: Trim (empty Cut Set) → Remove whitespace
Step 2: Lowercase → Normalize case
Step 3: Validate format
Step 4: Process cleaned input
Pattern: Clean Scraped Data
Web scraped data often has extra whitespace:
Step 1: Trim whitespace
Step 2: Replace multiple spaces with single space
Step 3: Use cleaned data