I would like to separate each number in an int variable to an array (similar to ToCharArray
).
Let’s say I have the number 123, then I’d like to put that into an array which looks like this: [0,0,0,0,1,2,3]
(as the final step).
Is there a way of achieving this without converting it to a string first? Performance is key as it has to run on an iPhone 3GS as minimum.
Doing something like this works, but I’m afraid it might be way to intense (what do you think?):
private var numbers : int = 1234567; //This can be 0 to 9999999
private var numArray : int[] = [0,0,0,0,0,0,0]; //The array to store the int numbers
function Start () {
InvokeRepeating("NumToArray", 0, 0.1); //Or some other acceptable repeated value
}
function NumToArray () {
var numString : String = numbers.ToString();
var numCharArray : char[] = numbers.ToCharArray();
var pos : int = 6;
for (var i : int = numCharArray.Length-1; i>=0; i--) {
numArray[pos] = parseInt(scoreStringArray*.ToString());*
pos–;
}
}