Slicing an int in js/unityscript?
So, I have a int variable such as
var myuniqueversion = Random.Range(1000, 9000); // come up with a number 4 digits long
How do I store, say digit 2 of this in a new variable? I've tried:
var mydigit : int = myuniqueversion[1];
But this returns an error stating that the int does not support slicing.
If the myuniqueversion generated 1536, I'd be looking for digit 2 of myuniqueversion to be stored in the mydigit int variable, and to be 5 in this case.
Answer by Jessespike · Nov 16, 2015 at 02:46 AM
You can store the int as a string and then parse it back as an int. Substring can be used to return a specific digit.
var mydigit : int = int.Parse(myuniqueversion.ToString().Substring(1,1));
Your answer
Follow this Question
Related Questions
Is C# or javascript easier to understand? 2 Answers
How to make a player move up then forward using ontrigger enter collider? 0 Answers
Error BCE0051 with script JS 1 Answer
I cant figure out why my array is causing the error 'System.Type' does not support slicing. 0 Answers
Error FormatException: Input string was not in a correct format. 0 Answers