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
.

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

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.

In both examples, the output will be the same.

You must be logged in to post a comment.