Practice 3- Switch

Hi, Im new in Uipath so understand some steps are hard.

Im doing practice 3 - Switch in Variables, Data Types and Control Flow, but I don’t get completely 1 step( I try doing by myself but its hard because i dont know functions that are used in the solution, I guess it’s normal and in the future I will be capable to do it).

This is the solution:

Practice 3 Solution

  1. Create the first Array of strings variable with default value of {“Ax001”,“Ax002”,“Ax003”,“Ax004”,“Ax005”,“Bx001”,“Bx002”,“Bx003”,“Cx001”,“Cx002”,“Cx003”,“Cx004”}

  2. Create 3 Array of strings variables and instantiate them in the default by using new string(){}

  3. Use a ‘For Each’ loop to iterate through the initial array and:

  4. Use a ‘Switch’ inside the loop with the expression built to extract the first 2 letters using the ‘Substring’ method : item.Substring(0,2).ToLower

  5. For each of the 3 cases (“ax”, “bx”, “cx”), use the ‘Concat’ method to add the item to the corresponding Array: i.e. axArray.Concat({item}).ToArray

  6. Use 3 ‘Log Message’ activities to print the content of each of the 3 Arrays, by using the ‘String.Join’ method : i.e. string.Join(" ",bxArray).

All goes well except for I don’t understand how the program identifies exactly Ax, Bx or Cx.

I mean, you have your switch activity, default is done, ok, we go to the case ax that contain "axArray = axArray.Concat({item}).ToArray

When I read this, I understant that the variable “axArray” concat all the item variable, but actually it just add all Ax error, exclusively… That 's the part where I have problems to understand.

axArray.Concat ({item}). ToArray where this says to add only ax error?

Can you share your code ?

else you can ping me on sg2070156@gmail.com

"axArray = axArray.Concat({item}).ToArray

In Switch Activity, We have a condition in which we are getting First 2 value of each item and then based on ax , bx and cx it will divide and then added into array type variable.

image

1 Like

sorry, as a new user i can’t attach any file. and i tried to upload impr pant image but cannot too, sorry.

These images are from the solution .zip. I had deleted my code before your answer.

In the solution, there is a index variable located in the For each output Field but i don’t know exactlt its purpose

Yes, i understand that too, but how can discern from “Ax, Bx and Cx” ? item.substring(0,2) only select the first two value if im not wrong, but how can differentiate A, B and C? that is what i don’t get it .

and the “.ToLower” function is to lower case the variable yh? so it’s transform from “Ax” to “ax” and go on…

the name defined in “case” will be the filter later?

Switch Activity check automatically and it passes those item those cases condition is true like Case ax: check if item contain contain ax or not if yes then assign value into AxArray otherwise check same for bx or cx

1 Like

ok, perfect, thanks