Create a dynamic List/Array

Hello,

I will describe below my current flow, but the main problem is how to create a dynamic list/array to store the values and later I want to sum them.

  1. Read PDF Text: I will read the PDF file and convert it to TXT:
  2. Assign - Array: Split(strText,Environment.NewLine) - The output above I will create line by line to read those strings in For Each and get what I need via Regex;
  3. For Each: strArrayText (list of items) and always when I find the RegEx code I want, I want to store in the variable and here it starts my problem because I have this FOR EACH looping, hence always when the RegEx code finds what I want, I want to store it in a list/array…

I created a new assign called:

  1. strList = new List(of String)()

And here I tried so far everything (Append, Items to collection) but those methods just allow to store only ONE variable, while I have this FOR EACH looping where I’ll need to store 2, 3 or 5 variables and later SUM the numbers found…
Any ideas here?

Thank you!

Hi,

And here I tried so far everything (Append, Items to collection) but those methods just allow to store only ONE variable, while I have this FOR EACH looping where I’ll need to store 2, 3 or 5 variables and later SUM the numbers found…
Any ideas here?

Wouldn’t your variable contain new values for every iteration. So you could use append items to collection with only one variable.

Adding one element
Assign Activity:
strList = strList.Append(yourStringVar).ToList

Adding more elements:
strList = strList.Conct({yourStringVar1,yourStringVar2,yourStringVar3}).ToList

UPD1 -
For a use case of:

  • regex is used to find numbers
  • summing up the found numbers

just let us know the sample text and we align a solution approach more specific on this

1 Like

hi @Ruy_Codo am I right to understand that you are doing sth. like this:

step 1: read a pdf and convert to txt
step 2: split text line by line
step 3: for each line find every regex match and store it in a list

right?

When I use append it stays only one. I need to use this FOR EACH to always include new variables.

But the problem Peter is I’m using the FOR EACH, therefore I can have 01 string inserted or I can have 05 strings. If i use yourStringVar1, it is not dynamic.

Hi Julian,

Exactly. My struggle is as I can find only one string, or ten strings… So I need to have a dynamic ‘’ append ‘’.

first of all kindly note:

it is more straightforward for the discussion

About:

we gave the option of concat as well

we dont think so
grafik

And if a new text / token comes to process we can do it in the same way

grafik

as mentioned and also shown above in the samples

can also be done directly
grafik

So to end and conclude:

  • tell us your case in detail and we can better help. Lets try to avoid ping-pongs and XY-Problems

grafik

done with:

feel free to split it into part statements

Hi Peter,

  1. Would you mind attaching the file just for my reference?;
  2. When you used the Regex ‘’ TEXT PALLET HERE ‘’, but it can be different pallet names… That’s why on my Studio I was using For Each, to go through each line. Is there a way?

Thank you for your time and helping me!

  1. Read PDF Text and Split into Lines:
  • Use UiPath’s PDF activities to read the PDF content and assign it to a string variable (strText).
  • Use Split(strText, Environment.NewLine) to create an array of lines (strArrayText).

Declare arry
List strList = new List();

after getting the data from PDF you can get put this value one by using

strList.Add(extractedValue);

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