How to extract last name but with more than 2 words

Hi,

I have a task to extract last name, but how to extract last name if it contains more than 3 words?

If I use .First and .Last, this name will work :
John Doe

First : John
Last : Doe

But what if the name is John Doe Smith? I want the result to be like this :

First : John
Last : Doe Smith

Anyone can help with this? Without regex if possible too. Thanks :slight_smile:

Hi @Rhys18

Try this:

Assign Activity -> fullName = "John Doe Smith"
Assign Activity -> nameParts = fullName.Split(" "c)
Assign Activity -> firstName = nameParts(0)
Assign Activity -> lastName = String.Join(" ", nameParts.Skip(1))

Regards

Hi @Rhys18

fullName = "John Doe Smith"

firstName = fullName.Split(" "c)(0)

lastName = String.Join(" ", fullName.Split(" "c).Skip(1).ToArray())

Output:

image

Regards,

Hi @Rhys18

Check the below flow for better understanding:

fullName = "John Doe"

fullName = "John Doe Smith"

Regards

@Rhys18

you can use this

first - str.Split(" ",2)(0)
second - str.Split(" ",2)(1)

image

cheers

This one works like a charm!

Thank for the help guys :slight_smile:

1 Like

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