Fetch middle name from full name

Hi Devs,

I have to fetch the first,last and middle name from a full nameI am able to fetch first and last name .Can anyone help me to fetch middle name as well.

Thanks,
Riya

@Riya1,

If your full name going to have two spaces like “Firstname Middlename lastname” follow this:

strMiddleBame=strFullName.Split(" "c)(1).Trim()

Use this in assign activity.

Thanks,
Ashok :slightly_smiling_face:

Hi,

Can you try the following sample? This will work even if middle name does not exist.

m = System.Text.RegularExpressions.Regex.Match(fullName,"^(?<FIRSTNAME>\S+)\s+(?<MIDDLENAME>\S+\s+)?(?<LASTNAME>\S+)$")

Then

m.Groups("FIRSTNAME").Value
m.Groups("MIDDLENAME").Value
m.Groups("LASTNAME").Value

Sample
Sample20240815-1 (2).zip (2.7 KB)

note: If comma is also name separator, the following is better.

m = System.Text.RegularExpressions.Regex.Match(fullName,"^(?<FIRSTNAME>[^\s,]+)[\s,]+(?<MIDDLENAME>[^\s,]+[\s,]+)?(?<LASTNAME>[^\s,]+)$")

Regards,

Hello Riya

You can use Split on the names, and make a check (If sentence) wether they have 2 or 3 “parts” (3 = middle name present).

Take a look at the example:
Name.xaml (9.3 KB)

Regards,
Soren

Hi @Riya1

You are able to extract the First name and Last name right then store the data in two variables called var_FirstName and var_LastName.

Then use the Replace function to replace the First and last name from Full name.

Check the below expression to get the Middle name,

- Assign -> var_MiddleName = var_Fulname.Replace(var_FirstName.toString, "").Replace(var_LastName.toString, "").toString.Trim

The var_MiddleName will store the middle name in the Full name.

Hope it helps!!

Hi @ashokkarale ,

Getting below error: syntax error ‘,’ expected
The name ‘c’ does not exist in current context.

Do we need to use diff syntax as i am using c# lang.

Thanks,
Riya

@Riya1,

Ohh ok. Use Split Text activity then.

Output:
image

Thanks,
Ashok :slight_smile:

@ashokkarale ,

Split text activity is not available in 2019 version of UiPath.

Thanks,
Riya

Hi @Yoichi ,

Below expression is not working in C#.

Thanks,
Riya

@Riya1,

Ok no problem!

Use this expression.

This will split the full name into array of string

strArray = strFullName.Split(' ',StringSplitOptions.RemoveEmptyEntries)

Get index[1] value that is middle name.

strMiddleName = strArray[1]

Sample code:

Sample Xaml:
Main.xaml (8.0 KB)

Output:
image

Thanks,
Ashok :slight_smile:

Hi,

Can you try as the following?

strFullName = "FirstName MiddleName LastName"
m = System.Text.RegularExpressions.Regex.Match(strFullName,@"^(?<FIRSTNAME>[^\s,]+)[\s,]+(?<MIDDLENAME>[^\s,]+[\s,]+)?(?<LASTNAME>[^\s,]+)$")

Then

m.Groups["FIRSTNAME"].Value
m.Groups["MIDDLENAME"].Value
m.Groups["LASTNAME"].Value

Sample
Sample20240815-2LCS.zip (2.3 KB)
(If this cannot be opened, can you try to replace project.json with one which is created in your Studio?)

Regards,

Hi @ashokkarale ,

Getting below error:

Thanks,
Riya

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