0% found this document useful (0 votes)
186 views

UiPath String Manipulation

The document discusses common string manipulation methods in UiPath including Contains, StartsWith, EndsWith, Format, Replace, and Split. It provides examples of how to use each method to check if a string contains or starts/ends with a substring, format strings, replace characters or substrings, and split a string into an array.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
186 views

UiPath String Manipulation

The document discusses common string manipulation methods in UiPath including Contains, StartsWith, EndsWith, Format, Replace, and Split. It provides examples of how to use each method to check if a string contains or starts/ends with a substring, format strings, replace characters or substrings, and split a string into an array.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

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(“The quick”) True

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

String.Format(“My name is {0} and I am {1} years My name is John and I am 21


old.”,”John”,”21″) years old.

String.Format(“Today is {0}.”,”Monday”) Today is Monday.


https://docs.microsoft.com/en-us/dotnet/api/system.string.format?view=netframework-4.8

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.

stringVar = “apple, orange, mango”

Syntax Result

stringVar.Replace(“,”,”;”) apple; orange; mango

stringVar.Replace(“a”,”i”) ipple, oringe, mingo

stringVar.Replace(“a”,”ASD”) ASDpple, orASDnge, mASDngo

stringVar.Replace(“”,”;”) Error
https://docs.microsoft.com/en-us/dotnet/api/system.string.replace?view=netframework-4.8

Split
I use the method when I want to split a string into a number of substrings. The method returns an Array of Strings.

Examples
Split the given text by comma.

stringVar = “apple, orange, mango”

Syntax Result

stringVar.Split(“,”) {“apple”,”orange”,”mango”}

You might also like