cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
aarnav
Advocate I
Advocate I

Break a number into array of digits

hi all,

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?

aarnav_0-1662948442453.png

 

aarnav_1-1662948467217.png

 

 

Split function used, EmployeeID contains the number 789545

 

split(split(items('Apply_to_each_2')?['EmployeeID'],'')[0],'')
 

thanks

5 REPLIES 5
Sundeep_Malik
Community Champion
Community Champion

Hey @aarnav

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:

Sundeep_Malik_0-1662966835695.png

Here is the Output:

Sundeep_Malik_1-1662966854866.png

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.

Sundeep_Malik_2-1662968928101.pngSundeep_Malik_3-1662968988198.png

 

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')

 

Sundeep_Malik_4-1662969146564.png

Variables F to store reverse array(The result you want).

Variable G: sub(length(variables('C')),1)
 
Sundeep_Malik_5-1662969285999.png

Apply to each loop, to get the final values:

Compose 2: variables('C')[variables('G')]

Append to Array 2: outputs('Compose_2')

 

 

Sundeep_Malik_6-1662969321831.png

 

Last compose to show the output:

 

Sundeep_Malik_7-1662969407387.png

 

 

I hope you like the solution. If you have any doubts just comment.

VictorIvanidze
Community Champion
Community Champion

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')),' ')
--------------------------------------------------------------------------------------
Contact me if you are interested in custom Power Automate development.
Paulie78
Super User
Super User

This should do what you want:

 

ArrayOfDigits.png

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:

Remove unwanted characters with Power Automate 

The subject of the post isn't what you want to do, but it uses the same technique.

 

Blog: tachytelic.net

YouTube: https://www.youtube.com/c/PaulieM/videos

If I answered your question, please accept it as a solution 😘

Really elegant approach, @Paulie78. Bravo! 

--------------------------------------------------------------------------------------
Contact me if you are interested in custom Power Automate development.

Thanks @VictorIvanidze I love the range function, useful in so many situations.

Helpful resources

Announcements
Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Difinity Conference 2022

Difinity Conference 2022

Register today for two amazing days of learning, featuring intensive learning sessions across multiple tracks, led by engaging and dynamic experts.

European SharePoint Conference

European SharePoint Conference

The European SharePoint Conference returns live and in-person November 28-December 1 with 4 Microsoft Keynotes, 9 Tutorials, and 120 Sessions.

Users online (5,149)