I am trying to break a number into an array of digits using split function but it keeps giving the whole number as the first item of the array.
How can this be broken down into array items for each diigt?
Split function used, EmployeeID contains the number 789545
I have made a flow to get all digits of a number in an array. Its a little long, I hope you understand it.
Heres how the input looks like:
Here is the Output:
Variable A to store the number, variable C to store the digits, Variable D for index number, Variable E just stored variable A's temporary value. And also the condition for do until is given.
Inside Do Until: I am taking last digit of integer. And putting it in array. Its a reverse array.
Append to Array Value: mod(variables('E'),10)
Compose Value: div(variables('E'),10)
Set Variable: outputs('Compose')
Variables F to store reverse array(The result you want).
Apply to each loop, to get the final values:
Compose 2: variables('C')[variables('G')]
Append to Array 2: outputs('Compose_2')
Last compose to show the output:
I hope you like the solution. If you have any doubts just comment.
Try to use this:
split(trim(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(variables('strDigits'),'0',' 0'),'1',' 1'),'2',' 2'),'3',' 3'),'4',' 4'),'5',' 5'),'6',' 6'),'7',' 7'),'8',' 8'),'9',' 9')),' ')
This should do what you want:
The output generated from the select action is:
[ "7", "8", "9", "5", "4", "5" ]
If you want to understand better how this works, this blog post I wrote should help:
The subject of the post isn't what you want to do, but it uses the same technique.
If I answered your question, please accept it as a solution 😘
Really elegant approach, @Paulie78. Bravo!
Keep up to date with current events and community announcements in the Power Automate community.
A great place where you can stay up to date with community calls and interact with the speakers.
Check out the latest Community Blog from the community!