Montag, 25. März 2013

c#: lines count in big textfile

using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Count
{
    class Program
    {
        static void Main(string[] args)
        {
            string f = @"\"; //add name of file where you want to count the liens
            long count = 0;
            using (StreamReader r = new StreamReader(f))
            {
                     while ((r.ReadLine()) != null)
                {
                    count++;
                    if (count % 100000 == 0) //number indicates etap counts
                    {
                        System.Console.WriteLine(count.ToString() + " lines and counting");
                    }
                }
                System.Console.WriteLine(count.ToString() + " total lines");
                System.Console.ReadLine();
            }
        }
    }
}

Keine Kommentare: