To split the Full name string into first name and last name

I want to split the string into two strings as First name and Last name from the Full name string but the Full name string consists of multiple words in it .
Ex: Full name : YEKULA RAMESH SUNIL KUMAR

When i tried with below two lines
FullName.Split({" “},stringSplitOptions.RemoveEmptyEntries)(0) – YEKULA
FullName.Split({” "},stringSplitOptions.RemoveEmptyEntries)(1) – KUMAR

But i want the output to be First name – YEKULA , Last name – RAMESH SUNIL KUMAR

Can any one help me to solve this issue

@Vasundhara_Pakkurthi

Try like this.

  fullName = "YEKULA RAMESH SUNIL KUMAR"
   firstName = fullName.Split(" "c)(0)
   lastName = fullName.Replace(fullName.Split(" "c)(0),"")
6 Likes

Hi,

The following expressions will also work, FYI.

firstName = System.Text.RegularExpressions.Regex.Match(fullName,"^\w+").Value

lastName = System.Text.RegularExpressions.Regex.Match(fullName,"(?<=^\w+\s).+").Value

Regards,

Try this:
Fullname : YEKULA RAMESH SUNIL KUMAR
split = Fullname.Split(" “c)
firstname=split(0)
lastname=Fullname.Replace(firstname,”")

Working,
Thanks for reply

1 Like

@Vasundhara_Pakkurthi

Glad to help you. Happy Automation :slight_smile:

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