How can I merge two string arrays into a dictionary?


In my project I want the following arrays to be merged into a single dictionary with a key pair value of {array1,array2}

array1 = (“1”,“2”,“3”,“4”)
array2 = (“One”, “Two”, “Three”, “Four”)

What is the best approach to combine the two arrays?

Hi @tom_mccaffrey ,

We could Merge the two Arrays in to a Key Value Pair Dictionary type provided both the arrays have equal number of items in it. We can use the Expression below in an Assign Activity :

dictFromArrays = Enumerable.Range(0, numberList.Length).ToDictionary(Function(i)numberList(i),Function(i)wordsList(i))

Here, dictFromArrays is a Dictionary(Of String,String) type variable, numberList and wordsList are two Array of String type variables.


1 Like

we assume that the arrays are reliable of the same length

dictVar =
Enumerable.Range(0,array1.Length).toDictionary(Function (x) array1(x), Function (x) array2(x))

as an variation we also can do
array1.Select(Function (x,i) i).toDictionary(Function (x) array1(x), Function (x) array2(x))

Peter with the answer as always, appreciate it!

If you want the simple way to do it…




Thank you for the feedback.

@supermanPunch 's approach is using a similar idea. He just used other variable names. May I ask you flag his answer as solution in case you did not use my secoond presented option. Thank You.

1 Like

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