How To split the string to get last name

Hi @Bot_Learner1

To extract the last name from a string in UiPath, follow these steps using native UiPath activities like Assign and Log Message or Write Line to check the results.

Steps

  1. Use the Assign activity to define a variable named lastName.
  2. In the expression field for lastName, use the Split function to split the string by spaces and select the last element of the resulting array. For example:

lastName = Split(fullName, " ")(Split(fullName, " ").Length - 1)

  1. Here, fullName is the variable containing the complete name.
  2. Add a Log Message or Write Line activity to display lastName, confirming that only the last name is extracted.

This method splits the string by spaces and captures the last element.

Here is the project
Main.xaml (9.5 KB)

1 Like