Parsing Data

In general, parsing refers to the act of translating a string into meaningful type. In our game, we'll be parsing the string that hold values like dates and numbers into the coresponding types and do some calculation.

Now, back to our Main class. Now, we want to ReadSoccerResults and store it to the List, so we will be easier to manipulate the data.

public static List<string[]> ReadFootballResults(string fileName)
{
    var soccerResults = new List<string[]>();
    using (var reader = new StreamReader(fileName))
    {

    }
    return soccerResults;
}

Then, we need a looping function to iterate from beginning to the end of files until it reaches null.

public static List<string[]> ReadFootballResults(string fileName)
{
    var soccerResults = new List<string[]>();
    using (var reader = new StreamReader(fileName))
    {
        var line = "";
        while ((line = reader.ReadLine()) != null)
        {

        }
    }
    return soccerResults;
}

Then, we will split the value by comma (',') and store it to list array.

public static List<string[]> ReadFootballResults(string fileName)
{
    var soccerResults = new List<string[]>();
    using (var reader = new StreamReader(fileName))
    {
        var line = "";
        while ((line = reader.ReadLine()) != null)
        {
            string[] values = line.Split(',');
            soccerResults.Add(values);
        }
    }
    return soccerResults;
}

Try to run and look at the results.

results matching ""

    No results matching ""