Split String and Get First & Last Element using UiPath

Split a string and get the first and the last element using the UiPath. This is helpful in directly splitting a string using a single char and get the value.

Prerequisites

Add a new Assign activity and initialize a new string variable with a sample value. My variable name is name and its value is JD Bots.

Initialize a new string variable for splitting the string and get the first and last element in UiPath

I will split the name variable using space and print the first and second path of the string on the output console using the Write Line activity. Below is the expression I will be using to get the first and last element of a string in UiPath.

name.Split(" "c).First
name.Split(" "c).Last
Get the First and Last element of a string using UiPath

If you want to split the string based on a special character, for example, hyphen (-). Then your expression will be as shown below.

name.Split("-"c).First
name.Split("-"c).Last

Below is the complete flow for this example.

Split a string using hyphen and get the first and last element in UiPath

In both examples, the output will be the same.

Output showing split string example getting first and last element in UiPath

Thank you All!!! Hope you find this useful.


Up ↑

%d bloggers like this: