Paul Klink

A little bit about me

Paul Klink

Paul Klink

A little bit about me

Counting Records

This examples shows how the number of records CSV file can be calculated. It uses the Basic Example Meta File.

CSV File:

"Pet Name","Age","Color","Date Received","Price","Needs Walking","Type"
"","(Years)","","","(Dollars)","",""
Rover,4.5,Brown,12 Feb 2004,80,True,Dog
Charlie,,Gold,5 Apr 2007,12.3,False,Fish
Molly,2,Black,25 Dec 2006,25,False,Cat
Gilly,,White,10 Apr 2007,10,False,Guinea Pig

Console Application

using System;
using Xilytix.FieldedText;

namespace CountRecords
{
    class Program
    {
        // Simple Example of counting records in a CSV file.
        static void Main(string[] args)
        {
            // Name of file containing Meta
            const string MetaFileName = "BasicExampleMeta.ftm";
            // Name of file to be read
            const string CsvFileName = "BasicExample.csv";

            // Create Meta from file
            FtMeta meta = FtMetaSerializer.Deserialize(MetaFileName);

            // Create Reader
            using (FtReader reader = new FtReader(meta, CsvFileName))
            {
                // Use SeekEnd() instead of ReadToEnd() [quicker]
                reader.SeekEnd();

                Console.WriteLine(string.Format("Count: {0}",
                                                reader.RecordCount));
            }
        }
    }
}