Need to split name but dyamically specially middle name and please suggest

Hi ,

I have a string coming from website format of name = last name comma space first name space middle name(format :Nanag, Vinod kumar) & ).Need to split and saved into variable but the thing is sometimes middle name is not there and sometimes we have middle name( L, F) or (L,F M) .and uipath giving me an error on middle name when not there .please suggest how we make if condition or any other condition

Hi @PARAS_Singh,

yourValue = L,F M
valueArray = yourValue.Split(",“c)
lastName = valueArray(0)
firstName = If(valueArray(1).split(” “c).Count>1,valueArray(1).split(” “c)(1), valueArray(1).split(” “c)(0))
middleName = If(valueArray(1).split(” “c).Count>1,valueArray(1).split(” "c)(1), “”)

Regards,
MY

2 Likes

Hi,

Hope the following sample helps you.

m = System.Text.RegularExpressions.Regex.Match(item.Trim,"(?<LASTNAME>^\w+),\s?(?<MIDDLENAME>\w*)\s(?<FIRSTNAME>\w+$)")

Then,

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

Sample20220614-1.zip (2.5 KB)

Regards,

1 Like

Hi @muhammedyuzuak Thanks for the reply .when i used your method it showing middle name as first name and before this if you can see in picture there is space before james .please suggest

Hi @PARAS_Singh,

Sorry for the late return. Can you update as below. It meets all the conditions when I tested it, but if there is a test I missed, please add it.

valueArray=yourValue.Split(",“c)

firsName=valueArray(1).split(" ".ToArray,StringSplitOptions.RemoveEmptyEntries)(0)

midName=If(valueArray(1).split(" ".ToArray,StringSplitOptions.RemoveEmptyEntries).Count>1,valueArray(1).split(" ".ToArray,StringSplitOptions.RemoveEmptyEntries)(1), "")

1 Like

Thanks @muhammedyuzuak .

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