I use Visual Studio 8.7.9, Unity 2019.3.13f1
When I try to convert string[] to int[],
string score = reader.ReadToEnd();
string[] scores = score.Split('\n');
int[] scoreSorter = new int[scores.Length + 1];
for(int i =0; i <scores.Length; i++)
{
scoreSorter[i] = Convert.ToInt32(scores[i]);
foreach(var s in scoreSorter)
{
Array.Sort(scoreSorter);
Debug.Log(s);
highScore.text = "Рекорды: \n" + scoreSorter[0] + "\n" + scoreSorter[1] + "\n" + scoreSorter[2] + "\n" + scoreSorter[3];
}
}
I get this error in my unity console:
FormatException: Input string was not in a correct format. System.Number.StringToNumber (System.String str, System.Globalization.NumberStyles options, System.Number+NumberBuffer& number, System.Globalization.NumberFormatInfo info, System.Boolean parseDecimal) (at <437ba245d8404784b9fbab9b439ac908>:0) System.Number.ParseInt32 (System.String s, System.Globalization.NumberStyles style, System.Globalization.NumberFormatInfo info) (at <437ba245d8404784b9fbab9b439ac908>:0) System.Int32.Parse (System.String s, System.IFormatProvider provider) (at <437ba245d8404784b9fbab9b439ac908>:0) System.Convert.ToInt32 (System.String value) (at <437ba245d8404784b9fbab9b439ac908>:0) ButtonAction.ButtonClickHighScore () (at Assets/Scripts/UI/ButtonAction.cs:73)
My aim is to get each number in array, sort them and display on the scoreboard. Any help will be appreciated!