Add string items to a list

Hi community!
I am iterating over a table, for each line I store a string in a variable “X”, but for each time I iterate over this table I need to store this value in a comma-separated list, so that this list can be used later in a type into activity. I’m having trouble putting together this logic, could you please help me? Thanks!

@amanda.gondim,

No need to iterate through Datatable. Just use LINQ in Assign activity like this.

commaSeparatedList = String.Join(",", dataTable.AsEnumerable().Select(Function(row) row("YourColumnName").ToString()).ToArray())

Thanks,
Ashok :slight_smile:

Hello!
For each row in my table, I already do a search to return a string, as follows:
to: str_codNotaCredito
value: dt_extraidaQAD.Rows(int_indiceNC-1)(9).ToString()
and I need to store these values ​​in my array

Do you already have a List type variable where you want to store the strings? If not, that’s the first step.

Then, inside each iteration, you just append a new item (your string) to that list.

Logic would look like something like this:
For each row > extract the desired string > append that string to the list

Create a variable with datatype IEnumerable(of string) and then in the default put New List(Of String)

Then in your loop, use an Assign to set yourListVar = yourListVar.Concat({“new value to add”})

The new value can be a string variable or expression, just make sure it’s inside { and }

After the loop, yourListVar will be a list of the values, and you can get it as comma delimited by doing String.Join(",",yourListVar)

I use this method all the time and it works perfectly. Concatenating back to the same variable adds the new value (or values) onto the end.

no one was telling, that it will not work
we also mention the Append Operator which is for adding a single value.

Hello, I did exactly the step by step you described. But it only stored my last occurrence in the list, for example, it was supposed to save two values, the first was not saved, only the last. :frowning:
If you want, I’ll share the workflow. Thanks

@amanda.gondim did you try this approach?

You can just post a screenshot. If it’s only saving the last occurrence, that means you don’t have your Assign set up correctly.

On the left side of the assign just put your variable. On the right side of the assign put yourVariable.Concat({"new value"})

Sorry, my mistake. Fix it and it’s working perfectly. Thank you for the help!

1 Like

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