Mastering String Manipulation in UiPath: A Comprehensive Guide
Main points for "String Manipulation in UiPath":
1. Regex.Replace
The Regex.Replace method is used to replace text using regular expressions, allowing for more complex patterns than simple string replacements.
Example:
If you want to replace all digits with # in a string:
Text = "My number is 12345"
Result = System.Text.RegularExpressions.Regex.Replace(Text, "\d", "#")
Here, Result will be "My number is #####".
- Real-time example: You have a string
"My email is user@domain.com", and you want to mask the email username part:
Email = "user@domain.com"
MaskedEmail = System.Text.RegularExpressions.Regex.Replace(Email, "^\w+", "****") 'Output: "****@domain.com"
2. Right
The Right method is used to get a specified number of characters from the right side of a string.
Example: If you want the last 3 characters of a string:
Text = "Welcome"
Result = Text.Substring(Text.Length - 3)
Here, Result will be "ome".
- Real-time example: Extracting the last 2 digits of a phone number
"9876543210":
PhoneNumber = "9876543210"
LastTwoDigits = PhoneNumber.Substring(PhoneNumber.Length - 2) 'Output: "10"
3. TrimStart
The TrimStart method removes leading white-space characters from the start of a string.
Example:
Text = " Hello"
Result = Text.TrimStart() 'Output: "Hello"
- Real-time example: Removing leading spaces from a product code
" ABC123":
ProductCode = " ABC123"
TrimmedCode = ProductCode.TrimStart() 'Output: "ABC123"
4. Remove
The Remove method is used to delete a part of the string, starting at a specified position.
Example: You want to remove the first 5 characters from a string.
Text = "Welcome to UiPath"
Result = Text.Remove(0, 5)
Here, Result will be "to UiPath", as it removes the first 5 characters starting from index 0.
- Real-time example: Removing the domain part of an email
"user@example.com":
Email = "user@example.com"
ModifiedEmail = Email.Remove(Email.IndexOf("@")) 'Output: "user"
5. Left
The Left method is used to get a specified number of characters from the left side of a string.
Example: If you want to extract the first 3 characters of a string:
Text = "Welcome"
Result = Text.Substring(0, 3) 'or use Left as a custom function
Here, Result will be "Wel".
- Real-time example: Extracting the first 6 digits of a zip code
"1234567890":
ZipCode = "1234567890"
FirstPart = ZipCode.Substring(0, 6) 'Output: "123456"
6. TrimEnd
The TrimEnd method removes trailing white-space characters from the end of a string.
Example:
Text = "Hello "
Result = Text.TrimEnd() 'Output: "Hello"
- Real-time example: Removing trailing spaces from a product code
"XYZ123 ":
ProductCode = "XYZ123 "
TrimmedCode = ProductCode.TrimEnd() 'Output: "XYZ123"
7. Substring
The Substring method is used to extract a part of a string, starting at a specified position.
Example: You want to extract the first 4 characters from a string.
Text = "Hello World"
Result = Text.Substring(0, 4)
Here, Result will be "Hell". Substring(0, 4) means "start from index 0 and take 4 characters".
- Real-time example: You want to extract the date from
"2025-02-13":
DateString = "2025-02-13"
Date = DateString.Substring(0, 4) 'Output: "2025"
8. Split
The Split method is used to divide a string into an array of substrings based on a delimiter.
Example: Imagine you have a list of names, and you want to split the full name into first and last names.
FullName = "John Doe"
NameParts = FullName.Split(" "c)
Here, " " (space) is the delimiter, and NameParts will be an array containing ["John", "Doe"].
- Real-time example: You have an address
"123, Main St, New York", and you want to separate the parts based on commas:
Address = "123, Main St, New York"
AddressParts = Address.Split(","c)
AddressParts will contain ["123", " Main St", " New York"].
9. Replace
The Replace method is used to replace a specific part of a string with another string.
Example:
You want to replace "hello" with "hi" in a string.
Text = "Hello World"
Result = Text.Replace("Hello", "Hi")
Here, Result will be "Hi World".
- Real-time example: Replacing spaces with hyphens in a sentence
"Hello World":
Text = "Hello World"
ModifiedText = Text.Replace(" ", "-") 'Output: "Hello-World"
10. Trim, LTrim, RTrim
- Trim removes leading and trailing spaces.
- LTrim removes only leading spaces.
- RTrim removes only trailing spaces.
Example:
Text = " Hello World "
Trimmed = Text.Trim() 'Output: "Hello World"LeftTrimmed = Text.LTrim() 'Output: "Hello World "
RightTrimmed = Text.RTrim() 'Output: " Hello World"
- Real-time example: Cleaning a username
" user123 "before saving:
Username = " user123 "
CleanUsername = Username.Trim() 'Output: "user123"
🌟 Stay Ahead in RPA with UiPath 🌟
💡 Follow us for daily updates and exclusive insights into the world of Robotic Process Automation (RPA)!
🔍 Discover the Latest Trends
🚀 Master RPA Tools & Techniques
💼 Gain Expert Insights and Advice
👉 Be Part of the RPA Revolution Today!
🔔 Subscribe Now for Exclusive Content and Updates!
Comments
Post a Comment