Z
Z
Zefirot2021-11-12 17:14:59
C++ / C#
Zefirot, 2021-11-12 17:14:59

How to split a number into an array of numbers?

So far I am using this method

int ci = 12398;
string ac = ci.ToString();
int[] arrInt = new int[ac.Length];
for(int n = 0; n < ac.Length; ++n){ 
  arrInt[n] = int.Parse(ac[n]+ "");
  }

Debug.Log("ci = > " + ci);
Debug.Log("[0] = > " + arrInt[0]);
Debug.Log("[1] = > " + arrInt[1]);
Debug.Log("[2] = > " + arrInt[2]);
Debug.Log("[3] = > " + arrInt[3]);
Debug.Log("[4] = > " + arrInt[4]);

Maybe there is some more acceptable way?

Ps - Or even use any number without calculations, for example, pull out the 3rd number ...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
OneCellDM, 2021-11-12
@Zefirot

using System.Linq;
stringstr="12345";
int[] numbers = str.Select(x => int.Parse(x.ToString())).ToArray();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question