How To split the string to get last name

Hello Friends , I wanted to get last from below strings…Please Help.
e.g.

  1. SEIDE HEROLD
  2. HALL JAMES ALLEN
  3. JOSE O PRECIADO
  4. JASON J OAKS

OutPut should like below (Last Name Only)

1.HEROLD
2.ALLEN
3.PRECIADO
4.OAKS

Hi @Bot_Learner1

lastName = name.Split(" "c).Last()

Regards,

@Bot_Learner1

It work’s for sure. Can you please show the screenshot of your workflow

Regards,

1 Like

Hello , Thanks Actually there was extra white space …issues is resolve.

@Bot_Learner1

Try below

name.Trim.Split(" "c).Last()

Regards,

1 Like

Ohhhhh…thanks …i also notice it just now…thanks…i will mark this as solution but i have to delete this Screen shoot.

1 Like

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

Thanks for response …this works too.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.