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
- Use the Assign activity to define a variable named
lastName
. - In the expression field for
lastName
, use theSplit
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)
- Here,
fullName
is the variable containing the complete name. - 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)