Split the values of two variables and assign them

Hi All,

Im stuck near a logic and unable to retrieve the values from it. Below is the place where i need help.

ColVal1= "a,b,c"
ColVal2 = "1,2,3"

so my output should be a= 1, b=2 , c=3

Thanks in Advance.

@ppratz

  1. Use assign activity to initialize the values of variables
    ColVal1="a,b,c"
    ColVal2="1,2,3"

  2. Use Split to split the string and store that split values into an array type variable
    ColVal1.Split(","c)
    ColVal2.Split(","c)

  3. And just use message box or else anything to print the output
    OutputVal1(0)+"="+OutputVal2(0)+","+OutputVal1(1)+"="+OutputVal2(1)+","+OutputVal1(2)+"="+OutputVal2(2)

Hope this will help you

Regards,
Vrushali

In a later point i want to add one more values to the ColVal1 and ColVal2. , i.e., ColVal1=“a,b,c,d” and
ColVal2=“1,2,3,4” . I should change the code again, but in my case i dont want to change the code for every variable which is gets added to the ColVal1 and ColVal2 ?

@ppratz Here is your solution

dummy4.xaml (8.6 KB)

Hope this will help you

Regards,
Vrushali

Hi,

Do you want to get result as single string variable? If so, the following will work.

result = String.Join(",",colVal1.Split({","c}).Select(function(x,i) x+"="+colVal2.Split({","c})(i)).toArray)

If you want to correlate with each value, perhaps you should use dictionary as the following.

dict = colVal1.Split(","c).Zip(colVal2.Split(","c ), Function(k,v) New With {k,v}).ToDictionary(Function(a) a.k, Function(a) a.v)

Then dict(“a”) returns 1, dict(“b”) returns 2 etc…

note: dict is Dictionary(Of string, string) type

Regards,

Hi @ppratz

Below is the workflow for the same :-
MainPratik.xaml (10.6 KB)

Output :-

image

This workflow will run with any count of Character present in the String.

For Eg :-

  1. ColVal1="a,b,c"
    ColVal2="1,2,3"
  2. ColVal1="a,b,c,d"
    ColVal2="1,2,3,4"

Mark as solution and like it :slight_smile:

Happy Automation :raised_hands:

Best Regards
Er Pratik Wavhal :robot::man_technologist:t4: :computer:

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