Getting a digit at a certain position out of a number string

I know I can use split to take a text string and get the letter at a certain position that way, as in:

HELLO = H,E,L,L,O
position 2 = E

Is there a way to do the same with a number?
12345 = 1,2,3,4,5
position 2 = 2

(I tried using text strings for this, considered turning a number into text and then back into a number again, but that became wildly complex and I thought there must be some better way, like maybe a Haxe expression I haven’t been able to find?)

1 Like

you can set a text behaviour to the number

Number(out) → (set)Text

Then split that text just like you would for a word.
This method is pretty much just converting a number to a string; which allows you to split it.

You can use the “ToNumber” behavior to change the string back to a number

If you want to extract a letter in a word, you can split the text and put each letter into a list. Then you just use the one input on the list to get the letter you want.

For numbers, you can use the same string structure that I showed in the other post, but you use (A+"").charAt(1) to get the second position (0 is the first position).

But also you can do the same thing with the text method.

5 Likes

Thanks, it was the number string manipulations in particular that had me stuck!