UiPath String Manipulation
UiPath String Manipulation
String manipulation is the process of analyzing a given string and applying different methods in order
to replace, split, find characters or perform any other string transformations.
Knowing how to manipulate strings plays a crucial role in most text processing tasks. Some tasks can
be as simple as replacing a character meanwhile, others can be very complex. So, knowing all
possible string functions or methods can make your life much easier.
In this article, I will present the most common methods used by RPA developers:
Contains
StartsWith & EndsWith
Format
Replace
Split
Contains
I use the method to check whether a character or a sequence of characters exists in a given string.
The method returns a Boolean value. The comparison is case-sensitive. The search begins at the
first character position of this string and continues through the last character position. If the argument
is not defined, the method throws an exception.
Examples
Check if the given text contains a letter or a word.
stringVar = “The quick brown fox jumps over the lazy dog”
Syntax Result
stringVar.Contains(“fox”) True
stringVar.Contains(“Fox”) False
stringVar.Contains(“bear”) False
stringVar.Contains() Error
The second example returns False because the method is case-sensitive.
https://docs.microsoft.com/en-us/dotnet/api/system.string.contains?view=netframework-4.8
StartsWith & EndsWith
I use the method to check whether a given string starts or ends with a substring. The method returns
a Boolean value. The call is case-sensitive. If the argument is not defined, the method throws an
exception.
Examples
Check if the text begins or ends with a given letter or a word.
stringVar = “The quick brown fox jumps over the lazy dog”
Syntax Result
stringVar.StartsWith(“T”) True
stringVar.StartsWith(“The”) True
stringVar.StartsWith(“THE”) False
stringVar.StartsWith() Error
stringVar.EndsWith(“g”) True
stringVar.EndsWith(“G”) False
stringVar.EndsWith(“dog”) True
stringVar.EndsWith() Error
https://docs.microsoft.com/en-us/dotnet/api/system.string.startswith?view=netframework-4.8
https://docs.microsoft.com/en-us/dotnet/api/system.string.endswith?view=netframework-4.8
Format
From my point of view, this method is one of the most used String methods. I use it when I want to
replace an array of strings within a string template. The method returns a String value. It throws an
exception when the arguments are not defined or the format is wrong.
Examples
Syntax Result
Replace
I use the method when I want to replace a specific character or a string within a given string. The
method returns a String value. It throws an exception when the first argument is not defined or is
the empty string(“”).
Examples
Replace the comma with a semicolon, replace a letter with another letter, replace a letter with a string.
Syntax Result
stringVar.Replace(“”,”;”) Error
https://docs.microsoft.com/en-us/dotnet/api/system.string.replace?view=netframework-4.8