- Home /
Question by
TurboHermit · Jan 11, 2013 at 11:23 AM ·
arrayintparseseperate
Number parse
Hi. I'm trying to dissect an int into different separate ints. Is there a way to take eacht character/number in an int and parse it onto another int? If so, is there a way to put them into an array easily?
For example: 1305 becomes NumberArray : int[] that contains 1, 3, 0 and 5.
Comment
Or just spacing between characters would work too I guess =P
Best Answer
Answer by Psymon · Jan 11, 2013 at 11:35 AM
You can do a function like this :
//c#
void IntToIntArray(int numberToConvert, out int[] numberArray)
{
string sNumber = numberToConvert.ToString();
numberArray = new int[sNumber.Length];
for(int i = 0; i < numberArray.Length; i++)
{
numberArray[i] = int.Parse(sNumber[i].ToString());
Debug.Log(numberArray[i]);
}
}