Array index out of range

StreamReader fileReader = new StreamReader(filepath, true);

        //read the text file
        filecontent = fileReader.ReadToEnd();

        //close the file when done reading
        fileReader.Close();
        

        //split the text file into lines
        lines = filecontent.Split("

"[0]);

        //list of nodes and int's
        List<Vector3> nodesList = new List<Vector3>();
        List<int> intList = new List<int>();
        int mode = 0;

        Debug.Log(values.Length);

        for (int l = 0; l < lines.Length;l++)
        {
            
            values = lines[l].Split(new char[]{' '}, StringSplitOptions.RemoveEmptyEntries);
            if( values[0] == "NODES")
            {
                mode = 1;
                break;
            }
            
            if( values[0] == "TRIANGLES")
            {
                mode = 2;
                break;
            }

i get the error(Array index out of range) at the if(values[0] == Nodes)

i don’t understand why it is giving the error.

I would be very thankfull if somebody could explain what i did wrong.

thank you in advance

Maybe Split return empty array and you try to access to first element which just isn’t exist. You should check it earlier:if(values.Length > 0). I hope this helps.