Substing of variable Text

Hi Everyone!

I have stumbled upon yet another conundrum while using UiPath. For an assignment I am working on, I am extracting data out of PDF which is always different from pdf to pdf. (they are forms by customers).
I need to extract the first name out of it, and than split the First name from the Second/Third/Fourth name. (the latter may be in one variable / separate from the FirstName variable). I have already managed to split all names in an Array (Name.Split(convert.ToChar(" ")), But I when I let this run on a pdf.file that contains only a first name without extra names, It evidently gives me the error index was outside the bounds of the array .
Can somebody point me towards a correct method of getting this split to work on either a Form that only has a first name (giving an empty variable for further names without throwing an error) and on forms with multiple names? (The names come from a filled in table in a PDF file, which I extract using Get Text.)

Hi @KDJ

Before making the split, you can place an IF activity to evaluate if the Variable Name contains a space or not using this expression : Name.Contains(" ").

You can then place the part of Name.Split(convert.ToChar(" ") in the Then part and the process of one Name in the else side.

1 Like

Hi @reda, Thank you for your answer.
How will I know how many names are in the split? because I have to use the data recovered to be entered into another Tool. So I Need to know how to include all of the names, or just make it split one time…

Kind Regards
Kdj

Well once you split your data using Name.Split(" "c) and you assign it to some variable (Namearray for exemple) you can use this variable to calculate how many names you have, using NameArray.length.

Ok, thanks again.

But can you instruct me on how to advance from here? I’ve put into a variable names.length.tostring. And k
now I need in another variable the output of Names minus the 1st one. How do you proceed to enter this into an assign activity?

Kind Regards
Karel

Hi @KDJ

I didn’t quite understand the last question, but if you try to access each separate name you can simply use indexes in the array NameArray like NameArray(0) to access the first name …

Hope this helps

Hello @Reda
Sorry for the late response, but it was the holidayseason…
What i mean is the following. When I am extracting the information (name), Sometimes the name is just X, other times it’s X Y Z. So In case it’s only X, I need X in one variable. In the other case, I need X in one variable, and Y Z in another. That’s why I am struggling, because in the last case. when I use nameArray(1), an error will be thone because there is no Y Z.
Does this make sence?

Thanks again!
KDJ

Hi @KDJ
As been said before

Using this If Activity you can place the case where there is no Y Z in the then section.

And the actions based on the split in the else section.

Hey @reda

Thanks once again, I already put that into my workflow. But the issue is that I never now how many names there are going to be. It might be X Y Z, but X Y Z K L M O P K J D, as well. So I can not put NameArray(1) + NameArray(2) + NameArray(3) because I don’t know beforehand how many names there are going to be. So if there are 3 names, and the Variable contains Namearray(5), I’m going to get an error… Is there anyway to like get the variable to contain NameArray(1 until maximum Array)?

Kind Regards
KDJ

Create a new string and then use a foreach activity and each time in an Assign activity add the new item to string created and place it in the same string this way you don’t have to worry about the indexes.

Thanks @reda, I’m already getting somewhere now :wink:
So sorry to ask you another follow-up question, as you can see i’m fairly new to Uipath.
How do I let the ForEach loop skip the first entry so that it will not be included into the variable?
the assign in the foreach loop is SecondNames=secondnames + " " + item

Kind regards
Kdj

Hi @KDJ

well if we suppose that all of the names are different, place an assign after and outside the foreach activity where you assign to secondNames the expression secondNames.replace(Names(0)+" “,”")

Regards,
Reda

It works! Thank you very much @reda . Really helped me a lot here!
Have a nice day!

Kind Regards
KDJ

Glad it works
Regards,
Reda

[close thread by marking the right answer as solution]

1 Like

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