Removing suffix or characters prior to a period

Hey guys,
I am new to UiPath and I have a problem. I have a list of names and I would like to remove suffix/ their middle name and keep their first and last name. For example
Alex J. Washington . I would like to remove “J.” and keep Alex Washington.
Ronald W. Harave Jr. I would like to remove “W.” and “Jr.” and keep Ronald Harave.
How can I achieve that ? Thanks!

Hi @Nabeel_Rana,

If the question only have these two situations, then you can use the solution as below:

originalFullName1.Split({" “},StringSplitOptions.RemoveEmptyEntries)(0)+” “+originalFullName1.Split({” "},StringSplitOptions.RemoveEmptyEntries)(2)

Thanks,
Aisling

Hi @Nabeel_Rana

If the string you want to remove is always something like " J.", " W." and etc… in the name.

Please try the below sample and see if this is what you need.

RemoveMiddleName.zip
(11.9 KB)

Cheers

1 Like

Thank you for the reply and I apologize for late reply, I was preparing for hurricane. Anyways, there are different names and the names provided in the question are just examples. However, thank you for the reply, but if you could explain what is going on then that would be awesome to learn. Thanks

@Allenliaw Thank you for the reply and I apologize for late reply, I was preparing for hurricane. This works perfectly, but if you could explain the command as well that would be awesome. I am actually inputting from excel file so now I have to take care of any space at the beginning of each name.

Also, When i do not have any suffix, it removes the last name. For example, Johnny Page turns to Johnny . How can I avoid that ?

Hi @Nabeel_Rana

I have updated the sample and attached it.

So this command is using regex, and for the following command it read the fullName(input string), check with the regex pattern “(\s[^\s]+. )”, the pattern is looking for the keyword between " " and “. “, found the match and replace it with single space " “, then use Trim to remove the space at the beginning and end.
System.Text.RegularExpressions.Regex.Replace(fullName,”(\s[^\s]+. )”,” ").Trim

The sample code will first output the regional string which content space at the beginning of the name, and second output print out the string after remove the middle name.

If you would like know more about regex, please check the following link.

The new updated sample code should take care the problem of Johnny Page example.
RemoveMiddleName v2.zip (12.2 KB)

Cheers

Hi @Nabeel_Rana

Welcome to the uipath community!

cheers :smiley:

Happy learning :smiley:

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