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
Create the first Array of strings variable with default value of {“Ax001”,“Ax002”,“Ax003”,“Ax004”,“Ax005”,“Bx001”,“Bx002”,“Bx003”,“Cx001”,“Cx002”,“Cx003”,“Cx004”}
Create 3 Array of strings variables and instantiate them in the default by using new string(){}
Use a ‘For Each’ loop to iterate through the initial array and:
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
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
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?
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.
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…
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
Hi @AlvaroHG Thanks for bringing up this post, I have few doubts too.
@Sagar_Gupta1 your explanations are clear, thank you. below are my questions:
in the expression item.Substring(0,2).ToLower what is the function of “0” and “2” , I understand 2 meaning it is extracting first two letter, but still I need some more clarity.
in the expression axArray.Concat({item}).ToArray can you please help me understand why are we using round brackets “()” and flower brackets “{}”
Make the Default value for your Arrays: Ax, Bx and Cx = “new string(){}”. Just copy it into the Default box for each. This makes the arrays dynamic. The arrayname.concat({item}).ToArray assigns the Values to each item.