# Sorting values in string-array by first numbers

**URL:** <https://forum.makecode.com/t/sorting-values-in-string-array-by-first-numbers/18179>\
**Category:** Show & Tell\
**Created:** [February 26, 2023, 8:56pm UTC](https://forum.makecode.com/t/sorting-values-in-string-array-by-first-numbers/18179 "2023-02-26T20:56:40Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![technonux](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/technonux/32/7924_2.png) [@technonux](https://forum.makecode.com/u/technonux)\
**Post date:** [February 26, 2023, 8:56pm UTC](https://forum.makecode.com/t/sorting-values-in-string-array-by-first-numbers/18179/1 "2023-02-26T20:56:40Z")

</div>

for example. if i had a array with the values  
{"10 print ‘Hello world!’ ", “5 lbl start”, "15 goto start’}  
it world sort it to  
{“5 lbl start”, "10 print ‘Hello world!’ ", “15 goto start”}

---

<div class="post-metadata">

**Author:** ![randomuser](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/randomuser/32/32505_2.png) [@randomuser](https://forum.makecode.com/u/randomuser)\
**Post date:** [February 26, 2023, 9:19pm UTC](https://forum.makecode.com/t/sorting-values-in-string-array-by-first-numbers/18179/2 "2023-02-26T21:19:27Z")

</div>

This is doable! You could have the code recognize the first characters before the first space, translate into numbers, and then replace the original array with the sorted array. If you want I can make up an example!

---

<div class="post-metadata">

**Author:** ![technonux](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/technonux/32/7924_2.png) [@technonux](https://forum.makecode.com/u/technonux)\
**Post date:** [February 26, 2023, 11:08pm UTC](https://forum.makecode.com/t/sorting-values-in-string-array-by-first-numbers/18179/3 "2023-02-26T23:08:09Z")

</div>

Sure, could you make an example?

---

<div class="post-metadata">

**Author:** ![randomuser](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/randomuser/32/32505_2.png) [@randomuser](https://forum.makecode.com/u/randomuser)\
**Post date:** [February 27, 2023, 1:43am UTC](https://forum.makecode.com/t/sorting-values-in-string-array-by-first-numbers/18179/4 "2023-02-27T01:43:06Z")

</div>

Sure! Its a bit late here, so i might send it tomorrow morning.

---

<div class="post-metadata">

**Author:** ![randomuser](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/randomuser/32/32505_2.png) [@randomuser](https://forum.makecode.com/u/randomuser)\
**Post date:** [February 27, 2023, 6:17pm UTC](https://forum.makecode.com/t/sorting-values-in-string-array-by-first-numbers/18179/5 "2023-02-27T18:17:33Z")

</div>

This should work!!

> **[Sort](https://arcade.makecode.com/S08528-36483-99606-12130)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

I made it versitle so it can handle any array length, as long as THERE ARE NO NUMBERS OTHER THAN THE POSITION MARKER IN THE TEXTS! it will get confused otherwise.

---

<div class="post-metadata">

**Author:** ![technonux](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/technonux/32/7924_2.png) [@technonux](https://forum.makecode.com/u/technonux)\
**Post date:** [February 27, 2023, 6:18pm UTC](https://forum.makecode.com/t/sorting-values-in-string-array-by-first-numbers/18179/6 "2023-02-27T18:18:53Z")

</div>

okay, send it whenever you want

---

<div class="post-metadata">

**Author:** ![technonux](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/technonux/32/7924_2.png) [@technonux](https://forum.makecode.com/u/technonux)\
**Post date:** [February 28, 2023, 11:06pm UTC](https://forum.makecode.com/t/sorting-values-in-string-array-by-first-numbers/18179/7 "2023-02-28T23:06:56Z")

</div>

Thank you!

---

<div class="post-metadata">

**Author:** ![robotosaurus](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/robotosaurus/32/19294_2.png) [@robotosaurus](https://forum.makecode.com/u/robotosaurus)\
**Post date:** [January 22, 2024, 10:50pm UTC](https://forum.makecode.com/t/sorting-values-in-string-array-by-first-numbers/18179/8 "2024-01-22T22:50:54Z")

</div>

This is exactly what I needed too!

---

<div class="post-metadata">

**Author:** ![randomuser](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/randomuser/32/32505_2.png) [@randomuser](https://forum.makecode.com/u/randomuser)\
**Post date:** [January 23, 2024, 7:53pm UTC](https://forum.makecode.com/t/sorting-values-in-string-array-by-first-numbers/18179/9 "2024-01-23T19:53:15Z")

</div>

Yay! : D
