Replace
Replaces all occurrences of a substring with another 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 original string.
- Old String - The substring to replace.
- New String - The replacement string.
Options
This node does not have configurable options.
Output
- Result - The string with all replacements applied.
How It Works
The Replace node finds all occurrences of the old string and replaces them with the new string:
- Replaces all occurrences - not just the first one
- Case-sensitive - "Hello" and "hello" are different
- Exact match - must match the old string exactly
- New string can be empty - effectively removes the old string
- Old string can be repeated - continues until no more matches
Usage Examples
Example 1: Replace Word
- String:
"Hello World, Hello Universe" - Old String:
"Hello" - New String:
"Hi" - Result:
"Hi World, Hi Universe"
Example 2: Remove Characters (Empty New String)
- String:
"(555) 123-4567" - Old String:
"(" - New String:
"" - Result:
"555) 123-4567"
Example 3: Replace Spaces
- String:
"Hello World Test" - Old String:
" " - New String:
"_" - Result:
"Hello_World_Test"
Example 4: Fix Typo
- String:
"The cat sat on teh mat" - Old String:
"teh" - New String:
"the" - Result:
"The cat sat on the mat"
Example 5: Replace Path Separator
- String:
"C:\\Users\\Documents" - Old String:
"\\" - New String:
"/" - Result:
"C:/Users/Documents"
Tips
- Replaces all occurrences, not just the first one
- Use empty New String to remove text
- Great for cleaning data (remove unwanted characters)
- Perfect for normalizing formats (dates, phone numbers, paths)
- Case-sensitive - use Lowercase/Uppercase first if needed
- Can be chained - multiple Replace nodes for complex transformations
Common Errors and Solutions
Error: Some occurrences not replaced
- Cause: Case sensitivity - "Hello" vs "hello"
- Solution: Convert to same case first, then replace
Error: Need to replace only first occurrence
- Cause: Replace works on all occurrences
- Solution: Use Index + Cut nodes for single replacement, or use more specific old string
Practical RPA Examples
Example: Clean Phone Number
String: "(555) 123-4567"
Step 1: Replace "(" with ""
Step 2: Replace ")" with ""
Step 3: Replace " " with ""
Step 4: Replace "-" with ""
Result: "5551234567"
Example: Normalize Date Format
String: "2024-01-15"
Old String: "-"
New String: "/"
Result: "2024/01/15"
Example: Remove HTML Tags (Simple)
String: "<p>Hello World</p>"
Step 1: Replace "<p>" with ""
Step 2: Replace "</p>" with ""
Result: "Hello World"
warning
For complex HTML, use dedicated HTML parsing tools.
Example: Sanitize Filename
String: "My Document: Version 2.0"
Step 1: Replace ":" with "-"
Step 2: Replace " " with "_"
Result: "My_Document-_Version_2.0"
Example: Fix CSV Encoding
String: 'Name,"Address","Phone"'
Old String: '""'
New String: '"'
Result: Properly escaped quotes
Example: Convert Windows to Unix Path
String: "C:\\Projects\\MyApp\\src"
Old String: "\\"
New String: "/"
Result: "C:/Projects/MyApp/src"
Pattern: Multi-Step Cleaning
Clean and normalize text data:
Step 1: Replace special characters
Step 2: Replace multiple spaces with single space
Step 3: Trim whitespace
Step 4: Lowercase
Result: Clean, normalized text
Pattern: Currency Formatting
Step 1: Replace "$" with ""
Step 2: Replace "," with ""
Step 3: ToNumber
Result: Numeric value
Example: "$1,234.56" → "1234.56" → 1234.56
Pattern: Data Masking
Mask sensitive data:
String: "User SSN: 123-45-6789"
Old String: "123-45-6789"
New String: "XXX-XX-XXXX"
Result: "User SSN: XXX-XX-XXXX"
Pattern: URL Encoding (Simple)
Replace special characters:
String: "Hello World"
Old String: " "
New String: "%20"
Result: "Hello%20World"
Advanced Use Cases
Remove All Digits
Chain multiple Replace nodes:
Replace "0" with ""
Replace "1" with ""
Replace "2" with ""
...
Replace "9" with ""
Standardize Separators
Input variations:
- "firstName,lastName"
- "firstName;lastName"
- "firstName|lastName"
Solution:
Replace ";" with ","
Replace "|" with ","
Result: All use comma separator
Clean Whitespace
Replace "\t" with " " (tabs to spaces)
Replace "\n" with " " (newlines to spaces)
Replace multiple spaces with single space